import java.util.Scanner; public class kie { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int n = Integer.parseInt(scanner.nextLine()); int[] A = new int[n]; int minOdd = Integer.MAX_VALUE; int oddCounter = 0; for (int i=0; i<n; i++) { A[i] = scanner.nextInt(); if (A[i] % 2 == 1) { minOdd = Math.min(minOdd, A[i]); oddCounter++; } } int sum = 0; for (int i=0; i<A.length; i++) sum += A[i]; int answer = 0; if (oddCounter % 2 == 1) { answer = sum - minOdd; } else { answer = sum; } if (answer == 0) System.out.println("NIESTETY"); else System.out.println(answer); } }
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 | import java.util.Scanner; public class kie { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int n = Integer.parseInt(scanner.nextLine()); int[] A = new int[n]; int minOdd = Integer.MAX_VALUE; int oddCounter = 0; for (int i=0; i<n; i++) { A[i] = scanner.nextInt(); if (A[i] % 2 == 1) { minOdd = Math.min(minOdd, A[i]); oddCounter++; } } int sum = 0; for (int i=0; i<A.length; i++) sum += A[i]; int answer = 0; if (oddCounter % 2 == 1) { answer = sum - minOdd; } else { answer = sum; } if (answer == 0) System.out.println("NIESTETY"); else System.out.println(answer); } } |