Solve of URI 1020 (Age in Days) in C
How to solve:
1. In this problem, we need to convert days into Year, Month and Days.
2. Input contains an integer, given as number of days.
3. First, we calculate hour by dividing input by 365 as 1 year contains 365 days, and save reminder in temp variable.
4. Then, calculate minute by dividing temp by 30 as 1 month contains 30 seconds.
5. And the reminder from minute is number of days.
6. Finally, print output as given format as problem description.
See sample input and output for better understanding with printing output.
Go through problem description and see my solution for clear concept. Thanks. :)
Solution in C:
//URI online judge 1020 solution in C
//This solution is made by Mehedi Hasan Kajol
#include<stdio.h>
int main(void){
long long int input,temp,year,month;
scanf(" %lld ", &input);
year = input / 365;
temp = input % 365;
month = temp / 30;
temp = temp % 30;
printf("%lld ano(s)\n%lld mes(es)\n%lld dia(s)\n", year, month, temp);
return 0;
}
Solution in C++:
//URI online judge 1020 solution in C++
//This solution is made by Mehedi Hasan Kajol
#include<iostream>
using namespace std;
int main(void){
long long int input,temp,year,month;
cin >> input;
year = input / 365;
temp = input % 365;
month = temp / 30;
temp = temp % 30;
cout<< year <<" ano(s)" << endl;
cout<< month <<" mes(es)" << endl;
cout<< temp <<" dia(s)" << endl;
return 0;
}