24h購物| | PChome| 登入
2012-05-15 20:20:18| 人氣1,397| 回應0 | 上一篇 | 下一篇

[UVA] 10070 - Leap Year or Not Leap Year and ...

推薦 0 收藏 0 轉貼0 訂閱站台

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

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.

大數是不是 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;
}

台長: Morris
人氣(1,397) | 回應(0)| 推薦 (0)| 收藏 (0)| 轉寄
全站分類: 不分類 | 個人分類: UVA |
此分類下一篇:[UVA] 725 - Division
此分類上一篇:[UVA][最小覆蓋圓] 10005 - Packing polygons

是 (若未登入"個人新聞台帳號"則看不到回覆唷!)
* 請輸入識別碼:
請輸入圖片中算式的結果(可能為0) 
(有*為必填)
TOP
詳全文