fork download
  1. #include <iostream>
  2. #include <vector>
  3. #include <algorithm>
  4. #include <string>
  5.  
  6. using namespace std;
  7.  
  8. int arr[27];
  9.  
  10. int main()
  11. {
  12. int A = 0;
  13. bool result = false;
  14. string s;
  15.  
  16. cin >> s;
  17.  
  18. for (int i = 0; i < s.size(); i++)
  19. {
  20. if (s[i] >= 'A' && s[i] <= 'Z')
  21. {
  22. A = s[i];
  23. A -= 65;
  24. arr[A]++;
  25. }
  26. else if (s[i] >= 'a' && s[i] <= 'z')
  27. {
  28. A = s[i];
  29. A -= 97;
  30. arr[A]++;
  31. }
  32. }
  33. int size = sizeof(arr) / sizeof(arr[0]);
  34. int curmax = 27, bemax = 27;
  35.  
  36. for (int i = 0; i < size;)
  37. {
  38. if (arr[curmax] <= arr[i])
  39. {
  40. bemax = curmax;
  41. curmax = i;
  42. }
  43.  
  44. if (curmax != 27 && bemax != 27
  45. && arr[curmax] == arr[bemax] && i > size-1)
  46. {
  47. cout << "?";
  48. result = true;
  49.  
  50. break;
  51. }
  52. i++;
  53. }
  54.  
  55. if (!result)
  56. {
  57. char B = curmax + 65;
  58. cout << B;
  59. }
  60.  
  61.  
  62.  
  63. }
  64.  
Success #stdin #stdout 0.01s 5276KB
stdin
Mississipi
stdout
S