fork download
  1. import java.io.*;
  2. import java.util.Arrays;
  3.  
  4. public class Main{
  5. public static void main(String[] args) throws IOException
  6. {
  7.  
  8. String str = br.readLine();
  9. int chars[] = new int[str.length()];
  10. int index = 0;
  11. int max = Integer.MIN_VALUE;
  12.  
  13. str =str.toUpperCase();
  14.  
  15. for(int i=0; i<str.length(); i++)
  16. {
  17. chars[i]=str.charAt(i);
  18. }
  19.  
  20. chars =Arrays.stream(chars).distinct().toArray();
  21.  
  22. int count[] = new int[chars.length];
  23.  
  24. for(int i=0; i<chars.length; i++)
  25. {
  26. for(int j =0; j<str.length(); j++)
  27. {
  28. if(chars[i] == str.charAt(j))
  29. {
  30. count[i]++;
  31. }
  32. }
  33. }
  34.  
  35. for(int i=0; i<count.length; i++)
  36. {
  37. if(max < count[i])
  38. {
  39. index = i;
  40. max = count[i];
  41.  
  42. }
  43. else if(max == count[i])
  44. {
  45. max = Integer.MIN_VALUE;
  46. break;
  47. }
  48. }
  49.  
  50. if(max == Integer.MIN_VALUE) System.out.println('?');
  51. else System.out.println((char)chars[index]);
  52.  
  53. }
  54. }
Success #stdin #stdout 0.1s 54052KB
stdin
abcc
stdout
?