Created
June 12, 2019 09:48
-
-
Save kei9327/efc338cec08bb3da75940029df18f835 to your computer and use it in GitHub Desktop.
HackerRank>Algorithm>implementation> Grading Students
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <bits/stdc++.h> | |
using namespace std; | |
/* | |
* Complete the gradingStudents function below. | |
*/ | |
vector<int> gradingStudents(vector<int> grades) { | |
vector<int> result; | |
result.reserve(grades.size()); | |
for (int i = 0; i < grades.size(); i++) { | |
int grade = grades[i]; | |
if (grade < 38) { | |
result.push_back(grade); | |
continue; | |
} | |
if((grade+1) % 5 == 0) { | |
result.push_back(grade+1); | |
} else if ((grade+2) % 5 == 0) { | |
result.push_back(grade + 2); | |
} else { | |
result.push_back(grade); | |
} | |
} | |
return result; | |
} | |
int main() | |
{ | |
ofstream fout(getenv("OUTPUT_PATH")); | |
int n; | |
cin >> n; | |
cin.ignore(numeric_limits<streamsize>::max(), '\n'); | |
vector<int> grades(n); | |
for (int grades_itr = 0; grades_itr < n; grades_itr++) { | |
int grades_item; | |
cin >> grades_item; | |
cin.ignore(numeric_limits<streamsize>::max(), '\n'); | |
grades[grades_itr] = grades_item; | |
} | |
vector<int> result = gradingStudents(grades); | |
for (int result_itr = 0; result_itr < result.size(); result_itr++) { | |
fout << result[result_itr]; | |
if (result_itr != result.size() - 1) { | |
fout << "\n"; | |
} | |
} | |
fout << "\n"; | |
fout.close(); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment