|
| 1 | +#include <bits/stdc++.h> |
| 2 | +using namespace std; |
| 3 | + |
| 4 | +vector<string> split_string(string); |
| 5 | + |
| 6 | +// Implemented Part |
| 7 | +vector<int> breakingRecords(vector<int> scores) { |
| 8 | + |
| 9 | + // Initialize highestScore and lowestScore to first value of scores |
| 10 | + // number of times she breaks her record i.e initialize 0 to countLow and countHigh |
| 11 | + int high = scores[0], low = scores[0], countHigh = 0, countLow = 0; |
| 12 | + vector<int> result; |
| 13 | + |
| 14 | + for(int i = 1; i < scores.size(); i++){ |
| 15 | + // compare current score with lowest score |
| 16 | + // if condition satisfies then do changes as given |
| 17 | + if(scores[i] < low){ |
| 18 | + countLow++; |
| 19 | + low = scores[i]; |
| 20 | + }else if(scores[i] > high){ |
| 21 | + // compare current score with highest score |
| 22 | + // if above condition satisfies then update the values |
| 23 | + countHigh++; |
| 24 | + high = scores[i]; |
| 25 | + } |
| 26 | + } |
| 27 | + |
| 28 | + // then push countHigh and countLow in returning vector i.e result |
| 29 | + result.push_back(countHigh); |
| 30 | + result.push_back(countLow); |
| 31 | + return result; |
| 32 | +} |
| 33 | + |
| 34 | +int main() |
| 35 | +{ |
| 36 | + ofstream fout(getenv("OUTPUT_PATH")); |
| 37 | + |
| 38 | + int n; |
| 39 | + cin >> n; |
| 40 | + cin.ignore(numeric_limits<streamsize>::max(), '\n'); |
| 41 | + |
| 42 | + string scores_temp_temp; |
| 43 | + getline(cin, scores_temp_temp); |
| 44 | + |
| 45 | + vector<string> scores_temp = split_string(scores_temp_temp); |
| 46 | + |
| 47 | + vector<int> scores(n); |
| 48 | + |
| 49 | + for (int i = 0; i < n; i++) { |
| 50 | + int scores_item = stoi(scores_temp[i]); |
| 51 | + |
| 52 | + scores[i] = scores_item; |
| 53 | + } |
| 54 | + |
| 55 | + vector<int> result = breakingRecords(scores); |
| 56 | + |
| 57 | + for (int i = 0; i < result.size(); i++) { |
| 58 | + fout << result[i]; |
| 59 | + |
| 60 | + if (i != result.size() - 1) { |
| 61 | + fout << " "; |
| 62 | + } |
| 63 | + } |
| 64 | + |
| 65 | + fout << "\n"; |
| 66 | + |
| 67 | + fout.close(); |
| 68 | + |
| 69 | + return 0; |
| 70 | +} |
| 71 | + |
| 72 | +vector<string> split_string(string input_string) { |
| 73 | + string::iterator new_end = unique(input_string.begin(), input_string.end(), [] (const char &x, const char &y) { |
| 74 | + return x == y and x == ' '; |
| 75 | + }); |
| 76 | + |
| 77 | + input_string.erase(new_end, input_string.end()); |
| 78 | + |
| 79 | + while (input_string[input_string.length() - 1] == ' ') { |
| 80 | + input_string.pop_back(); |
| 81 | + } |
| 82 | + |
| 83 | + vector<string> splits; |
| 84 | + char delimiter = ' '; |
| 85 | + |
| 86 | + size_t i = 0; |
| 87 | + size_t pos = input_string.find(delimiter); |
| 88 | + |
| 89 | + while (pos != string::npos) { |
| 90 | + splits.push_back(input_string.substr(i, pos - i)); |
| 91 | + |
| 92 | + i = pos + 1; |
| 93 | + pos = input_string.find(delimiter, i); |
| 94 | + } |
| 95 | + |
| 96 | + splits.push_back(input_string.substr(i, min(pos, input_string.length()) - i + 1)); |
| 97 | + |
| 98 | + return splits; |
| 99 | +} |
| 100 | + |
0 commit comments