fork download
  1. import java.util.Scanner;
  2.  
  3. public class Main {
  4. public static void main(String[] args) {
  5. Scanner scanner = new Scanner(System.in);
  6. int t = scanner.nextInt();
  7.  
  8. while (t-- > 0) {
  9. int n = scanner.nextInt();
  10. String number = scanner.next();
  11.  
  12. String result = isHelpfulNumber(n, number);
  13. System.out.println(result);
  14. }
  15. }
  16.  
  17. public static String isHelpfulNumber(int n, String number) {
  18. // Count the number of even and odd digits in the number
  19. int evenCount = 0;
  20. int oddCount = 0;
  21.  
  22. for (char digit : number.toCharArray()) {
  23. int num = digit - '0';
  24. if (num % 2 == 0) {
  25. evenCount++;
  26. } else {
  27. oddCount++;
  28. }
  29. }
  30.  
  31. // If there are at least two even digits, it's possible to make an even number
  32. if (evenCount >= 2) {
  33. return "Yes";
  34. }
  35. // If there's at least one even digit and n is greater than 1, it's possible
  36. else if (evenCount >= 1 && n > 1) {
  37. return "Yes";
  38. }
  39. // If all digits are odd and n is greater than 1, it's possible
  40. else if (oddCount >= 2 && n > 1) {
  41. return "Yes";
  42. }
  43. // Otherwise, not possible
  44. else {
  45. return "No";
  46. }
  47. }
  48. }
  49.  
Success #stdin #stdout 0.12s 43240KB
stdin
3
4
4783
4
3795
4
9742
stdout
Yes
Yes
Yes