#include <cstdio> int main() { int n, i, j, tmp; bool found = false; int suma = 0; scanf("%d", &n); int* tab = new int[n]; for(i=0; i<n; i++) { scanf("%d", &tab[i]); suma += tab[i]; } if (suma % 2 == 0 && suma > 0) printf("%d", suma); else { for (i=0; i<n; i++) { for (j=0; j<n-i-1; j++) { if (tab[j] > tab[j+1]) { tmp = tab[j]; tab[j] = tab[j+1]; tab[j+1] = tmp; } } } for (i=0; i<n; i++) { if (tab[i] % 2 == 1) { tmp = suma - tab[i]; if (tmp > 0) { printf("%d", tmp); found = true; } break; } } if (!found || suma <= 0) printf("NIESTETY"); } }
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 <cstdio> int main() { int n, i, j, tmp; bool found = false; int suma = 0; scanf("%d", &n); int* tab = new int[n]; for(i=0; i<n; i++) { scanf("%d", &tab[i]); suma += tab[i]; } if (suma % 2 == 0 && suma > 0) printf("%d", suma); else { for (i=0; i<n; i++) { for (j=0; j<n-i-1; j++) { if (tab[j] > tab[j+1]) { tmp = tab[j]; tab[j] = tab[j+1]; tab[j+1] = tmp; } } } for (i=0; i<n; i++) { if (tab[i] % 2 == 1) { tmp = suma - tab[i]; if (tmp > 0) { printf("%d", tmp); found = true; } break; } } if (!found || suma <= 0) printf("NIESTETY"); } } |