1 solutions

  • 0
    @ 2025-3-3 16:27:13

    C++ :

    #include <iostream>
    #include <cmath>
    using namespace std;
    int main()
    {
        int a[100000],i,j=0,k=0,l=0,n;
        cin>>n;
        for(i=1;i<=n;i++)cin>>a[i];
        for(i=1;i<=n;i++)
        {if((i%2)==0)l=l+a[i];
        else k=k+a[i];
        }
        j=abs(k-l);
        cout<<k<<endl<<l<<endl<<j<<endl;
        return 0;
    }
    
    

    Python :

    # coding=utf-8
    N=int(input())
    mylist=[]
    i=1
    while(i<=N):
        a=int(input())
        mylist.append(a)
        i=i+1
    #print(mylist)
    jihe=0
    ji=0
    ouhe=0
    ou=1
    while(ji<len(mylist)):
        jihe=jihe+mylist[ji]
        ji=ji+2
    print(jihe)
    while(ou<len(mylist)):
        ouhe=ouhe+mylist[ou]
        ou=ou+2
    print(ouhe)
    if(jihe>ouhe):
        print(jihe-ouhe)
    else:
        print(ouhe-jihe)
    
    • 1

    Information

    ID
    10161
    Time
    1000ms
    Memory
    128MiB
    Difficulty
    (None)
    Tags
    # Submissions
    0
    Accepted
    0
    Uploaded By