GDUFE ACM-1126

题目:http://acm.gdufe.edu.cn/Problem/read/id/1126

 

国庆作业系列——C.求某年月的天数

Time Limit: 2000/1000ms (Java/Others)

Problem Description:

   输入年号和月号,输出该月天数(例如输入2013 9,输出30)【1,3,5,7,8,10,12月是大月】

Input:

输入年,月

Output:

输出天数

Sample Input:

2014 10
2014 2

Sample Output:

31
28

思路:需要判断是否闰年,四年一闰,百年不闰,四百年再闰

难度:简单,就是要注意闰年是怎么规定的

代码:
 1 #include<stdio.h>
 2 int main()
 3 {
 4     int a,b;
 5     while(scanf("%d%d",&a,&b)!=EOF)
 6     {
 7         if(b==1||b==3||b==5||b==7||b==8||b==10||b==12)
 8             printf("31\n");
 9         else if(b==4||b==6||b==9||b==11)
10             printf("30\n");
11         else if(b==2)
12         {
13             if(a%100==0)
14             {
15                 if(a%400==0)
16                     printf("29\n");
17                 else printf("28\n");
18             }
19             else if(a%4==0)
20                 printf("29\n");
21             else printf("28\n");
22         }
23     }
24     return 0;
25 }

 

posted @ 2016-10-17 20:44  ruoruoruoruo  阅读(104)  评论(0编辑  收藏  举报