import java.util.Scanner; public class kie { private int result; private int left; private int smallestOdd = Integer.MAX_VALUE; private boolean even = true; public kie(int quantity) { left = quantity; } kie(int quantity, int[] values) { this(quantity); for (int i = 0; i < quantity; i++) { add(values[i]); } } final void add(int value) { result += value; if (value % 2 == 1) { even = !even; if (value < smallestOdd) { smallestOdd = value; } } left--; } public String result() { if (left != 0) { throw new IllegalStateException(left + " values are missing"); } if (!even && smallestOdd != Integer.MAX_VALUE) { result -= smallestOdd; } return result == 0 ? "NIESTETY" : String.valueOf(result); } public static void main(String[] args) { Scanner cin = new Scanner(System.in); int n = cin.nextInt(); kie kie = new kie(n); while (n-- > 0) { kie.add(cin.nextInt()); } System.out.println(kie.result()); } }
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 | import java.util.Scanner; public class kie { private int result; private int left; private int smallestOdd = Integer.MAX_VALUE; private boolean even = true; public kie(int quantity) { left = quantity; } kie(int quantity, int[] values) { this(quantity); for (int i = 0; i < quantity; i++) { add(values[i]); } } final void add(int value) { result += value; if (value % 2 == 1) { even = !even; if (value < smallestOdd) { smallestOdd = value; } } left--; } public String result() { if (left != 0) { throw new IllegalStateException(left + " values are missing"); } if (!even && smallestOdd != Integer.MAX_VALUE) { result -= smallestOdd; } return result == 0 ? "NIESTETY" : String.valueOf(result); } public static void main(String[] args) { Scanner cin = new Scanner(System.in); int n = cin.nextInt(); kie kie = new kie(n); while (n-- > 0) { kie.add(cin.nextInt()); } System.out.println(kie.result()); } } |