#include <iostream> using namespace std; int main() { int n; int sum=0; int smallest=0; cin >> n; int c[n]; for(int counter=0; counter<n; counter++) cin >> c[counter]; for(int counter=0; counter<n; counter++) sum=sum+c[counter]; if(sum%2==1 && n!=1) { for(int counter=0; counter<n; counter++) if(c[counter]%2==1) { smallest=c[counter]; break; } for(int counter=0; counter<n; counter++) if(c[counter]%2==1 && c[counter]<smallest) { smallest=c[counter]; } cout << sum-smallest; return 0; } else if(sum%2==0) cout << sum; else cout << "NIESTETY"; return 0; }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 | #include <iostream> using namespace std; int main() { int n; int sum=0; int smallest=0; cin >> n; int c[n]; for(int counter=0; counter<n; counter++) cin >> c[counter]; for(int counter=0; counter<n; counter++) sum=sum+c[counter]; if(sum%2==1 && n!=1) { for(int counter=0; counter<n; counter++) if(c[counter]%2==1) { smallest=c[counter]; break; } for(int counter=0; counter<n; counter++) if(c[counter]%2==1 && c[counter]<smallest) { smallest=c[counter]; } cout << sum-smallest; return 0; } else if(sum%2==0) cout << sum; else cout << "NIESTETY"; return 0; } |