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

RESTful APIs with CRUD Operations in Laravel 12| (2025)

  RESTful APIs serve as the foundation of modern web development. They follow a set of rules called Representational State Transfer (REST) t...

Powered by Blogger.