URI Online Judge | 1020 Age in Days (Solution)

Problem Link:
https://www.urionlinejudge.com.br/judge/en/problems/view/1020

URI Online Judge | 1020

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 n,y,m,d;
    scanf("%d",&n);
    y=n/365;
    m=(n%365)/30;
    d=(n%365)%30;
    printf("%d ano(s)\n%d mes(es)\n%d dia(s)\n",y,m,d);
    return 0;
}

Comments

  1. the selution by c++ :

    #include
    #include
    #include
    #include
    using namespace std;
    int main()
    {
    int N;
    int x;
    float y;
    int y1 ;
    float z;
    cin>>N;
    x = N/365;
    y = ((N/365.00)-x)*(365.00/30);
    y1 = y;
    z = (y-y1)*30;
    cout.precision(0);
    cout<<x<<" ano(s)"<<"\n"<<y1<<" mes(es)"<<"\n"<<fixed<<z<<" dia(s)"<<"\n";

    return 0;

    }

    ReplyDelete

  2. Output#include
    using namespace std;
    int main()
    {
    int a,y,m,d;
    int i=365,count=0;
    cin>>a;

    y=a/365;
    m=a%365/30;
    d=a%30;


    cout<<y<<" vano(s)"<<endl;
    cout<<m<<" mes(es)"<<endl;
    if(d==0)
    {
    cout<<d<<" dia(s)"<<endl;
    }
    else
    {

    i=a/i;

    cout<<d-i*5<<" dia(s)"<<endl;
    }

    }

    ReplyDelete

Post a Comment

Popular posts from this blog

URI Online Judge | 1036 Bhaskara's Formula (Solution)

URI Online Judge | 1043 Triangle (Solution)

URI Online Judge | 1042 Simple Sort (Solution)