URI Online Judge Solution 1279 Solution Leap Year or Not Leap Year and … Using Python Programming Language.
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.
InputInput 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) but can have more than 1000 digits.
OutputFor 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 | Sample Output |
2000 | This is leap year. |
Solution Using C++:
#include<iostream>
#include<string.h>
#include<cstdio>
using namespace std;
int split(string s,int len,int year)
{
int long long n=0;
for(int i=0;i<len;i++){
n=( n*10+ (s[i]-'0') )%year;
}
if(n==0)
return 0;
else
return 1;
}
int main()
{
char num[1000001];
unsigned long long len, n=0;
int x,y,z;
z=0;
while(cin>>num)
{
len=strlen(num);
if(z==1)
cout<<endl;
z=1;
y=0;
x=0;
if( split(num,len,4)==0 && split(num,len,100) !=0 || split(num,len,400)==0 ){
printf("This is leap year.\n");
y=1;
x=1;
}
if(split(num,len,15)==0){
printf("This is huluculu festival year.\n");
y=1;
}
if(split(num,len,55)==0 && x==1){
printf("This is bulukulu festival year.\n");
}
if(y==0)
printf("This is an ordinary year.\n");
}
return 0;
}
what is the logic,will you tell me?
ReplyDelete