[URI Online Judge] – 1020 – Age in Days

Read an integer value corresponding to a person’s age (in days) and print it in years, months and days, followed by its respective message “ano(s)”, “mes(es)”, “dia(s)”.

Note: only to facilitate the calculation, consider the whole year with 365 days and 30 days every month. In the test cases never will have a situation that allows 12 months and some days, like 360, 363 or 364. This is just an exercise for the purpose of testing simple mathematical reasoning.

Input

The input file contain 1 integer number.

Output

Print the output like the following example.

Sample Input Sample Output
400 1 ano(s)
1 mes(es)
5 dia(s)
800 2 ano(s)
2 mes(es)
10 dia(s)
30 0 ano(s)
1 mes(es)
0 dia(s)

Solution:

#include <cstdio>
int main(){
 int t, a = 0, m = 0, d = 0;
 scanf("%d", &t);
 if (t >= 365){
 a = t / 365;
 t %= 365;
 }
 if (t >= 30){
 m = t / 30;
 t %= 30;
 }
 d = t;
 printf("%d ano(s)\n", a);
 printf("%d mes(es)\n", m);
 printf("%d dia(s)\n", d);
 return 0;
}
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s