Algorithm


Problem Name: beecrowd | 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 cases of test there will never be 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 contains 1 integer value.

Output

Print the output, like the following example.

Input Sample Output Sample

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)

 

Code Examples

#1 Code Example with C Programming

Code - C Programming


#include <stdio.h>
int main()
{
 int n;

 scanf("%d", &n);

 int a = n / 365;
 int rA = n % 365;
 int rM = rA % 30;
 int m = rA / 30;
 int d = rM % 30;

 printf("%d ano(s)n%d mes(es)n%d dia(s)n", a, m, d);

 return 0;
}
Copy The Code & Try With Live Editor

Input

x
+
cmd
400

Output

x
+
cmd
1 ano(s) 1 mes(es) 5 dia(s)

#2 Code Example with C++ Programming

Code - C++ Programming



#include <iostream>

using namespace std;

int main()
{
 int n;
 
 cin >> n;
 
 int a = n / 365;
 int rA = n % 365;
 int rM = rA % 30;
 int m = rA / 30;
 int d = rM % 30;
 
 cout << a << " ano(s)" << endl << m << " mes(es)" << endl << d << " dia(s)" << endl;
 
 return 0;
}
Copy The Code & Try With Live Editor

Input

x
+
cmd
800

Output

x
+
cmd
2 ano(s) 2 mes(es) 10 dia(s)

#3 Code Example with Java Programming

Code - Java Programming


import java.util.Scanner;

public class Main {

 public static void main(String[] args) {
  int n;

  Scanner sc = new Scanner(System.in);
  n = sc.nextInt();

  int a = n / 365;
  int rA = n % 365;
  int rM = rA % 30;
  int m = rA / 30;
  int d = rM % 30;

  System.out.printf("%d ano(s)n%d mes(es)n%d dia(s)n", a, m, d);

 }
}
Copy The Code & Try With Live Editor

Input

x
+
cmd
30

Output

x
+
cmd
0 ano(s) 1 mes(es) 0 dia(s)
Advertisements

Demonstration


Previous
#1019 Beecrowd Online Judge Solution 1019 Time Conversion Solution in C, C++, Java, Python and C#
Next
#1021 Beecrowd Online Judge Solution 1021 Banknotes and Coins - URI 1021 Problem Solution in C, C++, Java, Python and C#