Skip to content

Instantly share code, notes, and snippets.

@GZShi
Created October 9, 2012 07:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save GZShi/3857174 to your computer and use it in GitHub Desktop.
Save GZShi/3857174 to your computer and use it in GitHub Desktop.
#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