-
Grading Students해커랭크(HackerRank) 2018. 8. 19. 17:41반응형
1. 문제
2. 알고리즘
키워드 - 구현
3. 코드
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364#include <bits/stdc++.h>using namespace std;/** Complete the gradingStudents function below.*/vector<int> gradingStudents(vector<int> grades) {/** Write your code here.*/vector<int> arr;int size = grades.size();for(int i = 0; i <size; i ++) {int cand = grades[i];int newGrade = ((cand / 5) + 1) * 5;if(newGrade < 40) {arr.push_back(cand);continue;}if(newGrade - cand < 3)arr.push_back(newGrade);elsearr.push_back(cand);}return arr;}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;}cs 반응형'해커랭크(HackerRank)' 카테고리의 다른 글
Birthday Cake Candles (0) 2018.08.19 Time Conversion (0) 2018.08.19 Day 0: Mean, Median, and Mode (0) 2018.08.19 Breaking the Records (0) 2018.08.19 Birthday Chocolate (0) 2018.08.19