#include <iostream>
using namespace std;
int main(){
int x,c,s,b,i;
x=0;
c=0;
s=0;
cin>>b;
int tab[b];
for(i=0;i<b;i++){cin>>tab[i];}
for(i=0;i<b;i++){
if (tab[i]%2==1){
if (c==0){c=tab[i];}
else {
if(x==0){x=tab[i];}
else {
if(c>x){
if(x<tab[i]){
s=s+tab[i]+c;
c=b;
}
else {
s=s+x+c;
c=tab[i];
}
}
else {
if(c<tab[i])
{s=s+tab[i]+x;}
else {
s=s+x+c;
c=tab[i];
}
}
}
}
}
else {s=s+tab[i];}
}
if (s==0){cout << "NIESTETY" << endl;}
else {cout <<s<<endl;}
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 | #include <iostream> using namespace std; int main(){ int x,c,s,b,i; x=0; c=0; s=0; cin>>b; int tab[b]; for(i=0;i<b;i++){cin>>tab[i];} for(i=0;i<b;i++){ if (tab[i]%2==1){ if (c==0){c=tab[i];} else { if(x==0){x=tab[i];} else { if(c>x){ if(x<tab[i]){ s=s+tab[i]+c; c=b; } else { s=s+x+c; c=tab[i]; } } else { if(c<tab[i]) {s=s+tab[i]+x;} else { s=s+x+c; c=tab[i]; } } } } } else {s=s+tab[i];} } if (s==0){cout << "NIESTETY" << endl;} else {cout <<s<<endl;} return 0; } |
English