HackerLand University has the following grading policy:
- Every student received a grade in the inclusive range from 0 to 100.
- Any grade less than 40 is a failing grade.
Sam is a professor at the university and likes to round each student according to these rules:
- If the difference between the grade and the next multiple of 5 is less than 3, round grade up to the next multiple of 5.
- If the value of the grade is less than 38, no rounding occurs as the result will still be a failing grade.
Example:
Input: n=4,grade[]={73,67,38,33}
Output:
75 67 40 33
Approach
C++
#include <bits/stdc++.h>using namespace std;int main(){int n = 4, i;int grade[n] = {73, 67, 38, 33};for (i = 0; i < n; i++){if (grade[i] >= 38){if (grade[i] % 10 > 2 && grade[i] % 10 < 5){if (grade[i] % 10 == 3)grade[i] = grade[i] + 2;elsegrade[i] = grade[i] + 1;}if (grade[i] % 10 > 7 && grade[i] % 10 <= 9){if (grade[i] % 10 == 8)grade[i] = grade[i] + 2;elsegrade[i] = grade[i] + 1;}}else if (grade[i] < 38){grade[i] = grade[i];}}for (i = 0; i < n; i++)cout << grade[i] << endl;return 0;}
No comments:
Post a Comment