Joao_Joao

Beecrowd 3141 - C

Jun 19th, 2022
1,205
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.90 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <malloc.h>
  4.  
  5. int main() {
  6.   size_t size = 52;
  7.   char date1[12], date2[12], *p;
  8.   p = (char*)malloc(size * sizeof(char));
  9.   getline(&p, &size, stdin);
  10.   p[strlen(p)-1] = '.';
  11.   scanf("%s%s", date1, date2);
  12.   int day1 = (date1[0] - '0') * 10 + (date1[1] - '0');
  13.   int day2 = (date2[0] - '0') * 10 + (date2[1] - '0');
  14.   int month1 = (date1[3] - '0') * 10 + (date1[4] - '0');
  15.   int month2 = (date2[3] - '0') * 10 + (date2[4] - '0');
  16.   int year1 = (date1[6] - '0') * 1000 + (date1[7] - '0') * 100 + (date1[8] - '0') * 10 + (date1[9] - '0');
  17.   int year2 = (date2[6] - '0') * 1000 + (date2[7] - '0') * 100 + (date2[8] - '0') * 10 + (date2[9] - '0');
  18.   int anos = year1 - year2 - 1 + ((month1 == month2 && day1 >= day2) || month1 > month2);
  19.   if(day1 == day2 && month1 == month2) printf("Feliz aniversario!\n");
  20.   printf("Voce tem %d anos %s\n", anos, p);
  21. }
  22.  
Advertisement
Add Comment
Please, Sign In to add comment