Codeforces 678B. The Same Calendar Solution
Solve in C:
#include <stdio.h>
int main()
{
int y,i,r=0,c=0,cl=0,flag=0,f,g;
while(scanf("%d",&y)!=EOF)
{
c=0,cl=0;
if((((y%4)==0)&&(y%100)!=0)||(y%400)==0)
{
f=1;
}
else
{
f=0;
}
r=0;
for(i=y+1; ; i++)
{
c++;
if((((i%4)==0)&&(i%100)!=0)||(i%400)==0)
{
cl++;
g=1;
}
else
{
g=0;
}
r=c+cl;
if(r%7==0&&f==1&&g==1)
{
break;
}
else if(r%7==0&&f==0&&g==0)
{
break;
}
}
printf("%d\n",i);
}
return 0;
}
#include <stdio.h>
int main()
{
int y,i,r=0,c=0,cl=0,flag=0,f,g;
while(scanf("%d",&y)!=EOF)
{
c=0,cl=0;
if((((y%4)==0)&&(y%100)!=0)||(y%400)==0)
{
f=1;
}
else
{
f=0;
}
r=0;
for(i=y+1; ; i++)
{
c++;
if((((i%4)==0)&&(i%100)!=0)||(i%400)==0)
{
cl++;
g=1;
}
else
{
g=0;
}
r=c+cl;
if(r%7==0&&f==1&&g==1)
{
break;
}
else if(r%7==0&&f==0&&g==0)
{
break;
}
}
printf("%d\n",i);
}
return 0;
}
No comments