目录
1.题目描述
描述
输入描述:
输出描述:
示例1
2.解题
1.题目描述
描述
KiKi想获得某年某月有多少天,请帮他编程实现。输入年份和月份,计算这一年这个月有多少天。
输入描述:
多组输入,一行有两个整数,分别表示年份和月份,用空格分隔。
输出描述:
针对每组输入,输出为一行,一个整数,表示这一年这个月有多少天。
示例1
输入:
2008 2复制输出:
29
2.解题
int main(){int year = 0;int mouth = 0;while ((scanf("%d %d", &year, &mouth)) != EOF){if (((year % 100 != 0) && (year % 4 == 0)) || (year % 400 == 0)){if (mouth == 2){printf("29\n");}else if (mouth == 1 || mouth == 3 || mouth == 5 || mouth == 7 || mouth == 8 || mouth == 10 || mouth == 12){printf("31\n");}else{printf("30\n");}}else{if (mouth == 2){printf("28\n");}else if (mouth == 1 || mouth == 3 || mouth == 5 || mouth == 7 || mouth == 8 || mouth == 10 || mouth == 12){printf("31\n");}else{printf("30\n");}}}return 0;}
第二种解法:
#include <stdio.h>
int main()
{int y = 0;int m = 0;int days[12] = {31,28,31,30,31,30,31,31,30,31,30,31}; while(scanf("%d%d", &y, &m) != EOF){int day = days[m-1];if((y%4==0 && y%100!=0) || (y%400==0)){if(m == 2)day += 1;}printf("%d\n", day);}return 0;
}