#include <iostream> #include <algorithm> using namespace std; /* run this program using the console pauser or add your own getch, system("pause") or input loop */ int t[1000000]; bool parzyste[1000000]; int main(int argc, char** argv) { int n,wynik=0,sw=0; cin >> n; int k; for(int i=0;i<n;i++) { cin >> k; if(n==1 && k%2!=0) { cout <<"NIESTETY"; return 0; } if(k%2==0) { wynik+=k; // cout << "parzyste :" << wynik << endl; } else { t[sw]=k; // cout<< "else :" << t[i]; sw++; } } //cout << "parzyste :" << wynik << endl; sort(t,t+sw); if(sw!=1) if(sw%2==1) {// cout << "nieparzyste" << endl; sw=sw-1; // cout << "sw :" << sw << endl; for(int i=sw;i>0;i--) { wynik+=t[i]; // cout << "tablica :"<< t[i]<< endl; } cout << wynik; return 0; } else { for(int i=0;i<sw;i++) { wynik+=t[i]; } cout << wynik; return 0; } cout << wynik; 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 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 | #include <iostream> #include <algorithm> using namespace std; /* run this program using the console pauser or add your own getch, system("pause") or input loop */ int t[1000000]; bool parzyste[1000000]; int main(int argc, char** argv) { int n,wynik=0,sw=0; cin >> n; int k; for(int i=0;i<n;i++) { cin >> k; if(n==1 && k%2!=0) { cout <<"NIESTETY"; return 0; } if(k%2==0) { wynik+=k; // cout << "parzyste :" << wynik << endl; } else { t[sw]=k; // cout<< "else :" << t[i]; sw++; } } //cout << "parzyste :" << wynik << endl; sort(t,t+sw); if(sw!=1) if(sw%2==1) {// cout << "nieparzyste" << endl; sw=sw-1; // cout << "sw :" << sw << endl; for(int i=sw;i>0;i--) { wynik+=t[i]; // cout << "tablica :"<< t[i]<< endl; } cout << wynik; return 0; } else { for(int i=0;i<sw;i++) { wynik+=t[i]; } cout << wynik; return 0; } cout << wynik; return 0; } |