# Daily HackerRank Challenge - Day 9

Daily HackerRank Challenge (30 Part Series)

This is a series of Daily HackerRank Challenge. Each day I show the some solutions written in C++.

HackerLand University has the following grading policy:

Every student receives a grade in the inclusive range from 0 to 100.
Sam is a professor at the university and likes to round each student's grade 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 grade is less than 38, no rounding occurs as the result will still be a failing grade.
For example, grade=84 will be rounded to 85 but grade=29 will not be rounded because the rounding would result in a number that is less than 40.

Given the initial value of grade for each of Sam's n students, write code to automate the rounding process.

Sample Input

4
73
67
38
33


Sample Output

75
67
40
33


The question states that there is no rounding if the value of grade is less than 38. We can print the input directly for this case.

if(s>=38){
// TODO
}
cout << s <<"\n";


If it is greater than or equal to 38, we need to find out the diff between the input and the next multiple of 5.

d=5-(s%5);


Check if the diff is less than 3, if so, add it to the input

if(d<3) s+=d;


Final Solution

int n,s,d;

int main()
{
FAST_INP;
cin >> n;
REP(i,n){
cin >> s;
if(s>=38){
d=5-(s%5);
if(d<3) s+=d;
}
cout << s <<"\n";
}
return 0;
}


# The Time in Words

At minutes=0, use o' clock. For 1 <= minutes <= 30 , use past, and for 30 < minutes use to. Note the space between the apostrophe and clock in o' clock. Write a program which prints the time in words for the input given in the format described. Sample Input

5
47


Sample Output

thirteen minutes to six


Since we need to convert the number to word, we can make a list for the convertion.

char nums[] = { "zero", "one", "two", "three", "four",
"five", "six", "seven", "eight", "nine",
"ten", "eleven", "twelve", "thirteen",
"fourteen", "fifteen", "sixteen", "seventeen",
"eighteen", "nineteen", "twenty", "twenty one",
"twenty two", "twenty three", "twenty four",
"twenty five", "twenty six", "twenty seven",
"twenty eight", "twenty nine",
};



We can just list out all the possible cases and select the corresponding numbers.

case 1: m==0
case 2: m==1
case 3: m==59
case 4: m==15
case 5: m==30
case 6: m==45
case 7: m<=30
case 8: m>30


Final Solution

int h,m;
char nums[] = { "zero", "one", "two", "three", "four",
"five", "six", "seven", "eight", "nine",
"ten", "eleven", "twelve", "thirteen",
"fourteen", "fifteen", "sixteen", "seventeen",
"eighteen", "nineteen", "twenty", "twenty one",
"twenty two", "twenty three", "twenty four",
"twenty five", "twenty six", "twenty seven",
"twenty eight", "twenty nine",
};

int main()
{
FAST_INP;
cin >> h >> m;

if (m == 0)
printf("%s o' clock\n", nums[h]);

else if (m == 1)
printf("one minute past %s\n", nums[h]);

else if (m == 59)
printf("one minute to %s\n", nums[(h % 12) + 1]);

else if (m == 15)
printf("quarter past %s\n", nums[h]);

else if (m == 30)
printf("half past %s\n", nums[h]);

else if (m == 45)
printf("quarter to %s\n", nums[(h % 12) + 1]);

else if (m <= 30)
printf("%s minutes past %s\n", nums[m], nums[h]);

else if (m > 30)
printf("%s minutes to %s\n", nums[60 - m], nums[(h % 12) + 1]);

return 0;
}


# Complete Code

Check out the complete code via below link

Daily HackerRank Challenge (30 Part Series)

### Discussion   