#12546:


v528255 (Random)

學校 : 國立成功大學
編號 : 50490
來源 : [119.14.82.57]
最後登入時間 :
2020-06-27 09:51:35
d047. 10070 - Leap Year or Not Leap Year and ... -- UVa10070 | From: [1.173.70.244] | 發表日期 : 2017-08-10 17:16

#include <stdlib.h>
#include <stdio.h>
#include <string.h>
char LeapYearOrNot(char *year,int Digits){
    int Last4Digits  = atoi(year+Digits-4);
    if(Last4Digits%4 == 0 && Last4Digits%100 != 0 || Last4Digits%400 == 0)
        return 'y';
    else
        return 'n';
}
char HuluculuOrNot(char *year,int Digits){ //15的倍數
    int i,Sum = 0;
    for(i=0;i<Digits;i++)
        Sum += year[i];
    if(Sum % 3 == 0 && (year[Digits-1] == '0' || year[Digits-1] == '5'))
        return 'y';
    else
        return 'n';
}
char BulukuluOrNot(char *year,int Digits){
    int i,Difference;
    for(i=0,Difference=0;i<Digits;i++){
        if(i % 2 == 0) Difference += year[i];
        else Difference -= year[i];
        
    }
    if(abs(Difference) % 11 == 0 && (year[Digits-1] == '0' || year[Digits-1] == '5'))
        return 'y';
    else
        return 'n';

}
int main(void){
    char *year = malloc(sizeof(char)*50);
    while(~scanf("%s",year)){
        char year_flag=0;
        int Digits = strlen(year);
        if(LeapYearOrNot(year,Digits) == 'y'){ 
            printf("This is leap year.\n");
            year_flag = 1;
        }
        if(HuluculuOrNot(year,Digits) == 'y'){ 
            printf("This is huluculu festival year.\n");
            year_flag = 1;
        }
        if(BulukuluOrNot(year,Digits) == 'y' && LeapYearOrNot(year,Digits) == 'y'){
            printf("This is bulukulu festival year.\n");
            year_flag = 1;
        }
        if(!year_flag)
            printf("This is an ordinary year.\n");
        printf("\n");
    } 
}
 
ZeroJudge Forum