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;
}



No comments

Most View Post

Recent post

Codeforces Round 925 (Div. 3) 1931D. Divisible Pairs Solution

    Problem Link  :   https://codeforces.com/contest/1931/problem/D S olution in C++: /// Author : AH_Tonmoy #include < bits / stdc ++. ...

Powered by Blogger.