Изменить 'du3/program.c'

This commit is contained in:
Pavlo Tverdyi 2020-03-26 10:41:57 +00:00
parent b5d8d03afd
commit 1db858f56d

View File

@ -1,10 +1,11 @@
#include <stdlib.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h>
#include <string.h> #include <string.h>
int main() int main()
{ {
char *str; char *str;
str = (char*) malloc(12); str = (char*) malloc(12);
scanf("%s",str); scanf("%s",str);
@ -12,21 +13,17 @@ int day=0;
int m=0; int m=0;
int y=0; int y=0;
sscanf(str, "%d.%d.%d", &day, &m, &y); sscanf(str, "%d.%d.%d", &day, &m, &y);
if( (day<0 || day>=31)||(m<0 || m>12)){
return 0;
}
day+=7; day+=7;
if(day>31 && m%2!=0){ if(m%2!=0 && day>31){
day-=31; day-=31;
m++; m++;
} }
else if(day>30 && m%2==0){ if(m%2==0 && day>30){
if(m==2 &&(y%400==0 ||(y%100!=0 && y%4==0))){ if(m==2 &&(y%400==0 ||(y%100!=0 && y%4==0))){
day-=29; day-=29;
} }
else{ else{
day-=31; day-=30;
} }
m++; m++;
} }
@ -34,10 +31,13 @@ if(m>12){
m-=12; m-=12;
y++; y++;
} }
if(m>9){
printf(" %d.%d.%d\n",day,m,y); printf(" %d.%d.%d\n",day,m,y);
}
else{
return 0; printf(" %d.0%d.%d\n",day,m,y);
}
return 0;
} }