[UVA] 10070 - Leap Year or Not Leap Year and ...
Problem A
Leap Year or Not Leap Year and …
Input: standard input
Output: standard output
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 leapyear-->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
20003600
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.
大數是不是 4 的倍數 5 的倍數 3 的倍數 11 的倍數 ... 等
#include <stdio.h>
#include <string.h>
int main() {
char str[3000];
int first = 1;
while(scanf("%s", str) == 1) {
int four, odd = 0, even = 0, len = strlen(str);
int sum = 0, five = str[len-1]-'0', i;
sscanf(str+len-4, "%d", &four);
for(i = 0; i < len; i++)
sum += str[i]-'0';
for(i = len-1; i >= 0; i -= 2)
odd += str[i]-'0';
for(i = len-2; i >= 0; i -= 2)
even += str[i]-'0';
if(!first)
puts("");
first = 0;
int flag = 0;
if(four%4 == 0 && four%100 != 0 || four%400 == 0)
puts("This is leap year."), flag = 1;
if(sum%3 == 0 && five%5 == 0)
puts("This is huluculu festival year."), flag = 1;
if(five%5 == 0 && (odd-even)%11 == 0 && (four%4 == 0 && four%100 != 0 || four%400 == 0))
puts("This is bulukulu festival year."), flag = 1;
if(!flag)
puts("This is an ordinary year.");
}
return 0;
}