fork download
  1. import java.util.Scanner;
  2.  
  3. public class Main{
  4. public static void main(String[] args){
  5. Scanner in = new Scanner(System.in);
  6.  
  7. String s = in.next();
  8. s = s.toUpperCase();
  9.  
  10. int[] count = new int[26];
  11.  
  12. for(int i = 0; i < s.length(); i++){
  13. int a = s.charAt(i);
  14. count[a-65]++;
  15. }
  16.  
  17. int max = count[0];
  18. int idx = 0;
  19.  
  20. for(int i = 1; i < 26; i++){
  21. if(count[i] > max){
  22. max = count[i];
  23. idx = i;
  24. }
  25. }
  26.  
  27. int resultCount = 0;
  28.  
  29. for(int i = 1; i < 26; i++){
  30. if(max == count[i])resultCount++;
  31. }
  32.  
  33. if(resultCount > 1){
  34. System.out.println("?");
  35. }else{
  36. System.out.println((char)(idx + 65));
  37. }
  38. }
  39. }
Success #stdin #stdout 0.14s 54504KB
stdin
ab
stdout
A