Wednesday, December 2, 2015

Uri problem 1020 solve

Problem :

Age in Days

Adapted by Neilor Tonin, URI  Brazil
Timelimit: 1
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 InputSample Output
4001 ano(s)
1 mes(es)
5 dia(s)
8002 ano(s)
2 mes(es)
10 dia(s)
300 ano(s)
1 mes(es)
0 dia(s)

Solution:


#include <stdio.h>
  
int main() {
  
 int input , year , months , days;
    scanf("%d",&input);
    year=(input/365);
    months=(input-(year*365))/30;
    days= input-((year*365)+(months*30));
    printf("%d ano(s)\n",year);
    printf("%d mes(es)\n",months);
    printf("%d dia(s)\n",days);
  
    return 0;
}

No comments:

Post a Comment