top1编程
← 返回题目
题解

【入门】奇数位偶数位和与差

1 条题解

  • 0
    @ 2026-7-28 22:10:13
    #include<bits/stdc++.h>
    using namespace std;
    int main(){
    	int a[1005],n,j=0,o=0;
    	cin>>n;
    	for(int i=1;i<=n;i++){
    		cin>>a[i];
    		if(i%2==0){
                o+=a[i];
            }
    		else{
                j+=a[i];
            }
    	}
    	cout<<j<<endl;
    	cout<<o<<endl;
    	if(j>o){
            cout<<j-o;
        }
    	else{
            cout<<o-j;
        }
    	return 0;
    }
    
    • 1