R. Age in Days
time limit per test
1 secondmemory limit per test
256 megabytesinput
standard inputoutput
standard outputGiven a Number N corresponding to a person's age (in days). Print his age in years, months and days, followed by its respective message "years", "months", "days".
Note: consider the whole year has 365 days and 30 days per month.
Input
Only one line containing a number N (0 ≤ N ≤ 106).
Output
Print the output, like the following examples.
Examples
input
Copy
400
output
Copy
1 years
1 months
5 days
input
Copy
800
output
Copy
2 years
2 months
10 days
input
Copy
30
output
Copy
0 years
1 months
0 days
my code:
#include<iostream>
using namespace std;
int main()
{
int n, y = 0, m = 0, d = 0;
cin >> n;
while(n >= 365)
{
y++;
n -= 365;
}
cout << y << " years\n";
while(n >= 30)
{
m++;
n -= 30;
}
cout << m << " months\n";
if(n < 30)
{
d += n;
}
cout << d << " days\n";
return 0;
}
No comments:
Post a Comment