fork download
  1. #include <iostream>
  2. #include <vector>
  3. #include <algorithm>
  4. using namespace std;
  5.  
  6. #define ll long long
  7.  
  8. int N;
  9. vector<ll> card;
  10.  
  11. int main()
  12. {
  13. ios::sync_with_stdio(false);
  14. cin.tie(NULL);
  15.  
  16. cin >> N;
  17. card.resize(N + 1);
  18. for (int i = 0; i < N; i++)
  19. {
  20. ll x;
  21. cin >> x;
  22. card[i] = x;
  23. }
  24.  
  25. vector<pair<int, ll>> card2;
  26. if (N == 1)
  27. {
  28. cout << card[0] << '\n';
  29. return 0;
  30. }
  31. else if (N == 2)
  32. {
  33. sort(card.begin(), card.end());
  34. cout << card[0] << '\n';
  35. return 0;
  36. }
  37. else
  38. {
  39. for (int i = 0; i < N - 1; i++)
  40. {
  41. int cnt = 1, error = 0;
  42. for (int x = 0; x < card2.size(); x++)
  43. {
  44. if (card2[x].second == card[i])
  45. {
  46. error = 1;
  47. break;
  48. }
  49. }
  50. if (error == 0)
  51. {
  52. for (int j = i + 1; j < N; j++)
  53. {
  54. if (card[i] == card[j])
  55. cnt++;
  56. }
  57. card2.push_back({ cnt , card[i] });
  58. }
  59. }
  60.  
  61. sort(card2.begin(), card2.end());
  62. reverse(card2.begin(), card2.end());
  63. int cnt = 0;
  64. if (card2.size() > 1 && card2[0].first == card2[1].first)
  65. {
  66. for (int i = 0; i < card2.size() - 1; i++)
  67. {
  68. if (card2[i].first == card2[i + 1].first)
  69. cnt = card2[i + 1].second;
  70. }
  71. cout << cnt << '\n';
  72. }
  73. else
  74. cout << card2[0].second << '\n';
  75.  
  76. return 0;
  77. }
  78. return 0;
  79. }
Success #stdin #stdout 0s 4400KB
stdin
2
1
2
stdout
0