Search Here

Monday, June 8, 2015

UVa - 10070 ( Leap Year Or Not .... )

Try Yourself First. For help Scroll Down .


Tip : Its an Easy problem . But a little bit logical. Read the problem statement carefully. It is said to find out a year is leap or any Festival year or not . But problem setter doesn't mention that a year will always be of 4 numbers. It may be more than 4 number. May be more than 18 digit. That means you have to take the year as a string. But how is it possible to find out a string is Leap or Any Festival Year or Not ? Yes, we have to analyse character by character and find the remainder of all 5 divisors ( 4, 100, 400, 15, 55 ) and multiply it by 10 until  the last character of the string. ( Yes . You guessed it . What we have done already at Kindergarten School . Just recall it. ) Finally you got the remainder of all divisor . Now check all the conditions those are in the problem statement .


Code :

#include<bits/stdc++.h>

using namespace std;

int main()
{
    string s;
    int loop=0;
    while(cin>>s)
    {
        int leap = 0, hulu=0, bulu=0;
        int len = s.size();
        int m4 = 0, m15=0, m55=0, m100=0, m400=0;
        if(loop>0)
            printf("\n");
        loop++;
        for(int i=0; i<len; i++)
        {
            m4 = (m4*10 + (s[i]-'0'))%4;
            m15 = (m15*10 + (s[i]-'0'))%15;
            m55 = (m55*10 + (s[i]-'0'))%55;
            m100 = (m100*10 + (s[i]-'0'))%100;
            m400 = (m400*10 + (s[i]-'0'))%400;
        }
        if(m4==0)
        {
            if(m100==0)
            {
                if(m400==0)
                    { printf("This is leap year.\n"); leap = 1; }
            }
            else
                { printf("This is leap year.\n"); leap = 1; }
        }
        if(m15==0)
            { printf("This is huluculu festival year.\n"); hulu = 1; }
        if(leap==1 && m55==0)
            { printf("This is bulukulu festival year.\n"); bulu = 1; }
        if(leap==0 && hulu==0 && bulu==0 )
            printf("This is an ordinary year.\n");
    }
    return 0;
}


=> Need help . Leave a Comment.

No comments:

Post a Comment