Created
October 9, 2012 07:28
-
-
Save GZShi/3857174 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <string.h> | |
#include <stdlib.h> | |
#define MAX_LEN 255 | |
#define TRUE 1 | |
#define FALSE 0 | |
int judge(char *str) | |
{ | |
int year = 0; | |
if(strlen(str) > 9) // 超出一个32bit能表示的最大位数 | |
{ | |
strcpy(str, str + strlen(str) - 4); | |
year = (str[0] - '0')*1000 + (str[1] - '0')*100 + (str[2] - '0')*10 + str[3] - '0'; | |
} | |
else | |
year = atoi(str); | |
return (((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0)); | |
} | |
int main(void) | |
{ | |
char str[MAX_LEN]; | |
char *s[2] = {"NO", "YES"}; | |
fscanf(str, MAX_LEN - 1, stdin); | |
printf("%s\n", s[judge(str)]); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment