Solution of 10070 - Leap Year or Not Leap Year and

Problem Description
source:https://uva.onlinejudge.org/external/100/10070.html

The ancient race of Gulamatu is very advanced in their year calculation scheme. They understand what leap year is (A year that is divisible by 4 and not divisible by 100 with the exception that years that are divisible by 400 are also leap year.) and they have also similar festival years. One is the Huluculu festival (happens on years divisible by 15) and the Bulukulu festival (Happens on years divisible by 55 provided that is also a leap year). Given an year you will have to state what properties these years have. If the year is not leap year nor festival year, then print the line ‘This is an ordinary year.’ The order of printing (if present) the properties is: leap year → huluculu → bulukulu. 

Input 

Input will contain several years as input. Each year will be in separate lines. Input is terminated by end of file. All the years will not be less than 2000 (to avoid the earlier different rules for leap years). 
    Please don’t assume anything else. 

Output 

For each input, output the different properties of the years in different lines according to previous description and sample output. A blank line should separate the output for each line of input. 
     Note that there are four different properties. 

Sample Input 

2000 
3600 
4515 
2001 

Sample Output 

This is leap year. 

This is leap year. 
This is huluculu festival year. 

This is huluculu festival year. 

This is an ordinary year.

Solution:

#include <algorithm>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <string>
#include <vector>
#include<stdio.h>

using namespace std;

int main()
{
    long int leap,set,len,i,mod4,mod100,mod400,mod15,mod55,flag;

    char year[10000];
    set=0;
    while(cin>>year)
    {

        if(set!=0)
            printf("\n");
        set=1;
        leap = flag = mod4 = mod100 = mod400 = mod15 = mod55 = 0;
        len = strlen (year);
        for (i=0; i< len; i++)
        {
            mod4 = ((mod4 * 10) + (year[i]-'0')) % 4;
            mod100 = ((mod100 * 10) + (year[i]-'0')) % 100;
            mod400 = ((mod400 * 10) + (year[i]-'0')) % 400;
            mod15 = ((mod15 * 10) + (year[i]-'0')) % 15;
            mod55 = ((mod55 * 10) + (year[i]-'0')) % 55;
        }

        if ((mod4==0 && mod100!=0) || mod400==0)
        {
            printf("This is leap year.\n");
            flag=1;
            leap=1;
        }

        if (mod15==0)
        {
             printf("This is huluculu festival year.\n");
             flag=1;
        }
        if(leap==1&& mod55==0)
            printf("This is bulukulu festival year.\n");
        if(flag==0)
            printf("This is an ordinary year.\n");
    }
    return 0;
}
image

No comments:

Post a Comment

Write your comment - Share Knowledge and Experience