fork download
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. class liczby
  6. {
  7. public:
  8. liczby(long cnt = 10);
  9. void append(long num);
  10. void appendc();
  11. bool search(long num);
  12. long count(long num);
  13. long get(long i);
  14. private:
  15. long indeks = 0;
  16. long *tab;
  17. };
  18.  
  19. liczby::liczby(long cnt)
  20. {
  21. tab = new long[cnt] {};
  22.  
  23. }
  24.  
  25.  
  26. void liczby::append(long num)
  27. {
  28. tab[indeks] = num;
  29. indeks++;
  30. }
  31.  
  32. void liczby::appendc()
  33. {
  34. cin >> tab[indeks];
  35. indeks++;
  36. }
  37.  
  38. bool liczby::search(long num)
  39. {
  40. for (long i = 0; i < indeks; i++)
  41. if (tab[i] == num) return true;
  42. return false;
  43. }
  44.  
  45. long liczby::count(long j)
  46. {
  47. long temp = 0;
  48. for (long i = 0; i < indeks; i++)
  49. if (tab[i] == tab[j]) temp++;
  50. return temp;
  51. }
  52.  
  53. long liczby::get(long i)
  54. {
  55. return tab[i];
  56. }
  57.  
  58.  
  59. int main()
  60. {
  61. long d, n;
  62. cin >> d;
  63. while (d--) {
  64. cin >> n;
  65. liczby tab(n);
  66. liczby testy((n + 1) / 2);
  67. for (long i = 0; i < n; i++)
  68. tab.appendc();
  69.  
  70. long temp{};
  71. for (long i = 0; i < n; i++) {
  72. temp = tab.get(i);
  73. if (testy.search(temp) == 1) continue;
  74. testy.append(temp);
  75.  
  76. if (tab.count(i)%2 == 1) break;
  77. }
  78. cout << temp << endl;
  79. }
  80. return 0;
  81. }
  82.  
  83.  
Success #stdin #stdout 0s 3416KB
stdin
2
5
4 4 4 4 4
7
2 3 8 8 8 2 8
stdout
4
3