Advertisement
Guest User

Untitled

a guest
Jun 25th, 2019
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.07 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 breakingRecords function below.
  8. vector<int> breakingRecords(vector<int> scores) {
  9. vector<int> result;
  10. result.reserve(2);
  11.  
  12. int minCount = 0;
  13. int maxCount = 0;
  14.  
  15. int min = scores[0];
  16. int max = scores[0];
  17.  
  18. for (int i = 1; i < scores.size(); i++) {
  19. int score = scores[i];
  20. if (score < min) {
  21. min = score;
  22. minCount++;
  23. }
  24.  
  25. if (scores[i] > max) {
  26. max = score;
  27. maxCount++;
  28. }
  29. }
  30. result.push_back(maxCount);
  31. result.push_back(minCount);
  32.  
  33. return result;
  34. }
  35.  
  36. int main()
  37. {
  38. ofstream fout(getenv("OUTPUT_PATH"));
  39.  
  40. int n;
  41. cin >> n;
  42. cin.ignore(numeric_limits<streamsize>::max(), '\n');
  43.  
  44. string scores_temp_temp;
  45. getline(cin, scores_temp_temp);
  46.  
  47. vector<string> scores_temp = split_string(scores_temp_temp);
  48.  
  49. vector<int> scores(n);
  50.  
  51. for (int i = 0; i < n; i++) {
  52. int scores_item = stoi(scores_temp[i]);
  53.  
  54. scores[i] = scores_item;
  55. }
  56.  
  57. vector<int> result = breakingRecords(scores);
  58.  
  59. for (int i = 0; i < result.size(); i++) {
  60. fout << result[i];
  61.  
  62. if (i != result.size() - 1) {
  63. fout << " ";
  64. }
  65. }
  66.  
  67. fout << "\n";
  68.  
  69. fout.close();
  70.  
  71. return 0;
  72. }
  73.  
  74. vector<string> split_string(string input_string) {
  75. string::iterator new_end = unique(input_string.begin(), input_string.end(), [] (const char &x, const char &y) {
  76. return x == y and x == ' ';
  77. });
  78.  
  79. input_string.erase(new_end, input_string.end());
  80.  
  81. while (input_string[input_string.length() - 1] == ' ') {
  82. input_string.pop_back();
  83. }
  84.  
  85. vector<string> splits;
  86. char delimiter = ' ';
  87.  
  88. size_t i = 0;
  89. size_t pos = input_string.find(delimiter);
  90.  
  91. while (pos != string::npos) {
  92. splits.push_back(input_string.substr(i, pos - i));
  93.  
  94. i = pos + 1;
  95. pos = input_string.find(delimiter, i);
  96. }
  97.  
  98. splits.push_back(input_string.substr(i, min(pos, input_string.length()) - i + 1));
  99.  
  100. return splits;
  101. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement