Advertisement
wojiaocbj

E3-C

Mar 19th, 2023
988
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.28 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <ctype.h>
  4. #include <string.h>
  5. #include <math.h>
  6. int leapyear(int year){
  7.     return (year % 400 == 0) || ((year % 4 == 0) && (year % 100 != 0));
  8. }
  9. int main(){
  10.     int n, year, month, day, hour, minute;
  11.     char input[64] = { 0 };
  12.     int monthdays[13] = { 0,31,28,31,30,31,30,31,31,30,31,30,31 };
  13.     fgets(input, 63, stdin);
  14.     sscanf(input, "%d", &n);
  15.     while(n--){
  16.         fgets(input, 63, stdin);
  17.         sscanf(input, "%d.%d.%d %d:%d", &year, &month, &day, &hour, &minute);
  18.         hour += (minute / 60);
  19.         minute %= 60;
  20.         day += (hour / 24);
  21.         hour %= 24;
  22.         while(month > 12){
  23.             month -= 12;year += 1;
  24.         }
  25.         if(leapyear(year)){
  26.             monthdays[2] = 29;
  27.         }
  28.         else{
  29.             monthdays[2] = 28;
  30.         }
  31.         while(day > monthdays[month]){
  32.             day -= monthdays[month];
  33.             month += 1;
  34.             if(month == 13){
  35.                 month = 1;year += 1;
  36.             }
  37.             if(leapyear(year)){
  38.                 monthdays[2] = 29;
  39.             }
  40.             else{
  41.                 monthdays[2] = 28;
  42.             }
  43.         }
  44.         printf("%04d.%02d.%02d %02d:%02d\n", year, month, day, hour, minute);
  45.     }
  46.     return 0;
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement