#include <stdio.h>
int is_leap_year(int y)
{
return (((y % 4 == 0) && (y % 100 != 0)) || (y % 400 == 0));
}
int main()
{
int y = 0;
int m = 0;
int d = 0;
int days[13] = { 0,31,28,31,30,31,30,31,31,30,31,30,31 };
while (scanf("%d%d", &y, &m) == 2)
{
d = days[m];
if ((is_leap_year(y) == 1) && (m == 2))
{
d++;
}
printf("%d\n", d);
}
return 0;
} #include <stdio.h>
int main() {
int year = 0;
scanf("%d", &year);
int month = 0;
do {
scanf("%d", &month);
switch (month) {
case 1 :
printf("31\n");
break;
case 2 : {
if (year % 4 == 0 || (year % 4 == 0 && year % 100 != 0 ) || year % 400 == 0) {
printf("29\n");
break;
} else {
printf("28\n");
break;
}
}
case 3 :
printf("31\n");
break;
case 4 :
printf("30\n");
break;
case 5 :
printf("31\n");
break;
case 6 :
printf("30\n");
break;
case 7 :
printf("31\n");
break;
case 8 :
printf("31\n");
break;
case 9 :
printf("30\n");
break;
case 10 :
printf("31\n");
break;
case 11 :
printf("30\n");
break;
case 12 :
printf("31\n");
break;
default : {
printf("输入错误月份,请重新输入:");
break;
}
}
} while ((scanf("%d", &year)) != EOF);
return 0;
} #include <stdio.h>
int main()
{
int y,m;
while(scanf("%4d %d",&y,&m) !=EOF)
//if either happens before any data could be successfully read, EOF is returned.
{
switch(m)
{
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12: //31天的月份
printf("31\n");
break;
case 4:
case 6:
case 9:
case 11: //30天的月份
printf("30\n");
break;
case 2:
if(y % 400 == 0 || (y % 4 == 0 && y % 100 != 0))//判断闰年
printf("29\n"); //闰年2月为28天
else
printf("28\n"); //平年为29天
}
}
return 0;
} #define _CRT_SECURE_NO_WARNINGS 1
#include <stdio.h>
int main()
{
int day[] = { 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
int y = 0;
int d = 0;
int input = 0;
while (scanf("%d%d", &y, &d) != EOF)
{
//是2月,进入闰年判断
if (2 == d)
{
//是闰年
if ((y % 4 == 0 && y % 100 != 0) || y % 400 == 0)
{
input = day[d] + 1;
}
//不是闰年
else
{
input = day[d];
}
}
//不是2月
else
{
input = day[d];
}
//输出结果
printf("%d\n", input);
}
return 0;
} #include <stdio.h>
void YearDay(int a, int b) {
int arr[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
int day = *(arr + b);// *(arr + b) == arr[b] 这两个相等
if (a % 4 == 0 && a % 100 != 0 || a % 400 == 0) {
if (b == 2) {
day++;
}
}
printf("%d\n", day);
}
int main() {
int a, b;
while (scanf("%d %d", &a, &b) != EOF) {
YearDay(a, b);
}
return 0;
}