1 条题解

  • 0
    @ 2023-3-13 12:11:09

    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;
    }
    
    

    Pascal :

    var i,k,n:longint; a:array[0..1] of longint;
    begin
      readln(n);
      for i:=1 to n do begin
        readln(k);
        inc(a[i mod 2],k);
      end;
      writeln(a[1]);
      writeln(a[0]);
      writeln(abs(a[0]-a[1]));
    end.
    
    

    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

    信息

    ID
    2094
    时间
    1000ms
    内存
    128MiB
    难度
    (无)
    标签
    递交数
    0
    已通过
    0
    上传者