fork download
  1. /*
  2.   INPUT:
  3. 1
  4.  
  5. 3
  6. John Doe
  7. Jane Smith
  8. Sirhan Sirhan
  9. 1 2 3
  10. 2 1 3
  11. 2 3 1
  12. 1 2 3
  13. 3 1 2
  14. */
  15.  
  16. #include <iostream>
  17. #include <vector>
  18. #include <sstream>
  19. #include <query>
  20.  
  21. using namespace std;
  22.  
  23. int main()
  24. {
  25. std::queue<std::string> queue_ = {"11"};
  26. int T;
  27. cin >> T;
  28.  
  29. string endingSeperator = "";
  30.  
  31. while (T--)
  32. {
  33. int n;
  34. cin >> n;
  35.  
  36. vector<string> names(n);
  37. vector<bool> eliminated(n, false);
  38.  
  39. cin.ignore();
  40.  
  41. for (int i = 0; i < n; ++i)
  42. getline(cin, names[i]);
  43.  
  44. string temp;
  45. getline(cin, temp);
  46.  
  47. vector<vector<int> > ratings;
  48.  
  49.  
  50. while (temp != "")
  51. {
  52. stringstream ss;
  53. ss << temp;
  54. vector<int> order(n);
  55.  
  56. for (int i = 0; i < n; ++i)
  57. {
  58. ss >> order[i];
  59. --order[i];
  60. }
  61.  
  62. ratings.push_back(order);
  63.  
  64. if (cin.eof())
  65. break;
  66.  
  67. getline(cin, temp);
  68. }
  69.  
  70. int numRatings = ratings.size();
  71. vector<int> posInRatings(numRatings, 0);
  72.  
  73. int winner = -1;
  74.  
  75. vector<int> count(n, 0);
  76.  
  77. for (int i = 0; i < numRatings; ++i)
  78. ++count[ratings[i][0]];
  79.  
  80.  
  81. while (winner == -1)
  82. {
  83.  
  84. for (int i = 0; i < numRatings; ++i)
  85. {
  86. bool changed(false);
  87. while (eliminated[ratings[i][posInRatings[i]]])
  88. {
  89. ++posInRatings[i];
  90. changed = true;
  91. }
  92.  
  93. if (changed)
  94. ++count[ratings[i][posInRatings[i]]];
  95. }
  96.  
  97. int highest(0);
  98.  
  99. int lowest(1000);
  100.  
  101. for (int i = 0; i < n; ++i)
  102. {
  103. if (eliminated[i])
  104. continue;
  105. if (count[i] > highest)
  106. highest = count[i];
  107.  
  108. if (count[i] < lowest)
  109. lowest = count[i];
  110. }
  111.  
  112. if (highest == lowest || highest * 2 > numRatings)
  113. winner = highest;
  114.  
  115. else
  116. {
  117. for (int i = 0; i < n; ++i)
  118. if (count[i] == lowest)
  119. eliminated[i] = true;
  120. }
  121. }
  122.  
  123. cout << endingSeperator;
  124. endingSeperator = "\n";
  125.  
  126. for (int i = 0; i < n; ++i)
  127. if (count[i] == winner && !eliminated[i])
  128. cout << names[i] << '\n';
  129. }
  130.  
  131. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp:19:17: fatal error: query: No such file or directory
compilation terminated.
stdout
Standard output is empty