Guest User

Untitled

a guest
May 25th, 2020
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.67 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. vector<string> split_string(string);
  6.  
  7. // Complete the climbingLeaderboard function below.
  8. vector<int> climbingLeaderboard(vector<int> scores, vector<int> alice) {
  9. map <int,int,greater<int>> mp;
  10. vector <int> ans;
  11. int c=0;
  12. for(int i=0;i<scores.size();i++){
  13. auto it =mp.find(scores[i]);
  14. if(it==mp.end()) mp[scores[i]]=c++;
  15. }
  16. for(int i=0;i<alice.size();i++){
  17. auto it= mp.upper_bound(alice[i]);
  18. if(it==mp.begin()){
  19. ans.push_back(1);
  20. continue;
  21. }
  22. it--;
  23. if(it->first==alice[i]) ans.push_back(it->second+1);
  24. else ans.push_back(it->second+2);
  25. }
  26. return ans;
  27. }
  28.  
  29. int main()
  30. {
  31. ofstream fout(getenv("OUTPUT_PATH"));
  32.  
  33. int scores_count;
  34. cin >> scores_count;
  35. cin.ignore(numeric_limits<streamsize>::max(), '\n');
  36.  
  37. string scores_temp_temp;
  38. getline(cin, scores_temp_temp);
  39.  
  40. vector<string> scores_temp = split_string(scores_temp_temp);
  41.  
  42. vector<int> scores(scores_count);
  43.  
  44. for (int i = 0; i < scores_count; i++) {
  45. int scores_item = stoi(scores_temp[i]);
  46.  
  47. scores[i] = scores_item;
  48. }
  49.  
  50. int alice_count;
  51. cin >> alice_count;
  52. cin.ignore(numeric_limits<streamsize>::max(), '\n');
  53.  
  54. string alice_temp_temp;
  55. getline(cin, alice_temp_temp);
  56.  
  57. vector<string> alice_temp = split_string(alice_temp_temp);
  58.  
  59. vector<int> alice(alice_count);
  60.  
  61. for (int i = 0; i < alice_count; i++) {
  62. int alice_item = stoi(alice_temp[i]);
  63.  
  64. alice[i] = alice_item;
  65. }
  66.  
  67. vector<int> result = climbingLeaderboard(scores, alice);
  68.  
  69. for (int i = 0; i < result.size(); i++) {
  70. fout << result[i];
  71.  
  72. if (i != result.size() - 1) {
  73. fout << "\n";
  74. }
  75. }
  76.  
  77. fout << "\n";
  78.  
  79. fout.close();
  80.  
  81. return 0;
  82. }
  83.  
  84. vector<string> split_string(string input_string) {
  85. string::iterator new_end = unique(input_string.begin(), input_string.end(), [] (const char &x, const char &y) {
  86. return x == y and x == ' ';
  87. });
  88.  
  89. input_string.erase(new_end, input_string.end());
  90.  
  91. while (input_string[input_string.length() - 1] == ' ') {
  92. input_string.pop_back();
  93. }
  94.  
  95. vector<string> splits;
  96. char delimiter = ' ';
  97.  
  98. size_t i = 0;
  99. size_t pos = input_string.find(delimiter);
  100.  
  101. while (pos != string::npos) {
  102. splits.push_back(input_string.substr(i, pos - i));
  103.  
  104. i = pos + 1;
  105. pos = input_string.find(delimiter, i);
  106. }
  107.  
  108. splits.push_back(input_string.substr(i, min(pos, input_string.length()) - i + 1));
  109.  
  110. return splits;
  111. }
Add Comment
Please, Sign In to add comment