#include <iostream> int main() { int amount = 0; std::cin >> amount; int smallestOdd = 1001; int bigSum = 0; int itWasOdd = 0; for(int i=0; i<amount; i++) { int number = 0; std::cin >> number; if(number < smallestOdd && number%2 != 0) { bigSum += smallestOdd; smallestOdd = number; itWasOdd = 1; } else { bigSum += number; } } bigSum -= itWasOdd*1001; if(bigSum%2 == 0 && bigSum != 0) { std::cout << bigSum << std::endl; } else if(itWasOdd && bigSum != 0) { bigSum += smallestOdd; std::cout << bigSum << std::endl; } else { std::cout << "NIESTETY" << std::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 | #include <iostream> int main() { int amount = 0; std::cin >> amount; int smallestOdd = 1001; int bigSum = 0; int itWasOdd = 0; for(int i=0; i<amount; i++) { int number = 0; std::cin >> number; if(number < smallestOdd && number%2 != 0) { bigSum += smallestOdd; smallestOdd = number; itWasOdd = 1; } else { bigSum += number; } } bigSum -= itWasOdd*1001; if(bigSum%2 == 0 && bigSum != 0) { std::cout << bigSum << std::endl; } else if(itWasOdd && bigSum != 0) { bigSum += smallestOdd; std::cout << bigSum << std::endl; } else { std::cout << "NIESTETY" << std::endl; } return 0; } |