import java.util.Scanner; public class Main{ public static void main(String[] args){ Scanner sc = new Scanner(System.in); while (sc.hasNext()) { int year = sc.nextInt(); int month = sc.nextInt(); switch (month){ case 2: if ((year%100==0 && year%400!=0) || year%4!=0){ System.out.println(28); }else { System.out.println(29); }; break; case 4:System.out.println(30);break; case 6:System.out.println(30);break; case 9:System.out.println(30);break; case 11:System.out.println(30);break; default: System.out.println(31); } } } }
# 查资料 # 首先要清楚月份天数的分类 # 每年的4,6,9,11月的天数都是30天 # 每年的1,3,5,7,8,10,12月都是31天 # 然后计算2月的天数 # 2月的天数有两种,闰年为29天,非闰年28天 # 判断是否为闰年的标准: # 四年一润,百年不一定润,四百年一定润。 # # 先判断百年吗?-->是-->是四百年吗?-->是-->闰年 # 先判断百年吗?-->是-->是四百年吗?-->不是-->平年 # 先判断百年吗?-->不是-->是4的倍数吗?-->是-->闰年 # 先判断百年吗?-->不是-->是4的倍数吗?-->不是-->平年 while True: try: m,n = map(int,input().split()) # m 为年, n 为月 a = [4,6,9,11] b = [1,3,5,7,8,10,12] if n in a: print(30) elif n in b : print(31) elif n ==2: if m % 100 ==0: # 是 百年 q = m /100 # 取前两位 if q % 4 ==0: # 是 四百年 -->闰年 2月29天 print(29) else: # 不是 四百年 -->平年 2月28天 print(28) else: # 不是 百年 if m % 4 ==0 : # 是 4的倍数 -->闰年 2月29天 print(29) else: # 不是 4的倍数 -->平年 2月28天 print(28) except: break # 扩展 # 判断可以合并 if (year % 4 == 0 and year % 100 != 0)&nbs***bsp;(year % 400 == 0): 符合就是闰年
# 运用了字典 day=0 while True: try: year,month=map(int,input().split()) if (year%4==0 and year%100!=0)&nbs***bsp;year%400==0: if month==2: day=29 else: if month==2: day=28 dic={1:31,2:day,3:31,4:30,5:31,6:30,7:31,8:31,9:30,10:31,11:30,12:31} print(dic[month]) except: break
#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; }
#include<stdio.h> int main(){ int year,month,day; while(scanf("%d %d",&year,&month)!=EOF){ //判断闰年,2月份多一天 if( (year % 4 == 0 && year % 100 !=0) || (year % 400 ==0) ){ if(month == 2) day=29; } else{ if(month == 2) day=28; } switch(month){ case 1:day=31;break; case 3:day=31;break; case 4:day=30;break; case 5:day=31;break; case 6:day=30;break; case 7:day=31;break; case 8:day=31;break; case 9:day=30;break; case 10:day=31;break; case 11:day=30;break; case 12:day=31;break; } printf("%d\n",day); } return 0; }
#include <stdio.h> int main(){ int year, month = 0; while(scanf("%d %d", &year, &month) != EOF){ switch(month){ default: printf("31\n"); break; case 4: case 6: case 9: case 11: printf("30\n"); break; case 2: if(year % 4 == 0 && year % 100 != 0 || year % 400 == 0) printf("29\n"); else printf("28\n"); break; } } return 0; }
#include<stdio.h> int main() { int year,month; while((scanf("%4d %2d",&year,&month))!=EOF){ switch(month){//这样省事些 case 1: case 3: case 5: case 7: case 8: case 10: case 12:printf("31\n");break; case 4: case 6: case 9: case 11:printf("30\n");break; case 2://2月单独拿出来 if(year%4==0&&year%100!=0||year%400==0) { printf("29\n"); break; } else { printf("28\n"); break; } } } }
#include<stdio.h> int main() { int year,month,day; while(~scanf("%d %d",&year,&month)) { switch(month) { case 1: case 3: case 5: case 7: case 8: case 10: case 12:printf("31\n");break; case 4: case 6: case 9: case 11:printf("30\n");break; default: if(year%400==0||(year%4==0&&year%100!=0)) printf("29\n"); else printf("28\n"); } } return 0; }
#include<stdio.h> int main () { int day = 0; int mouth = 0; int year = 0; while(scanf("%d %d",&year,&mouth)!=EOF) { //判断是否为闰年 if((year%4 == 0 && year%100 != 0) || year%400 == 0) { if(mouth == 2) { printf("%d\n",29); } else if(mouth == 4||mouth == 6|| mouth == 9|| mouth == 11) { printf("%d\n",30); } else { printf("%d\n",31); } } else { if(mouth == 2) { printf("%d\n",28); } else if(mouth == 4||mouth == 6|| mouth == 9|| mouth == 11) { printf("%d\n",30); } else { printf("%d\n",31); } } } return 0; }
/*获得月份天数*/ #include<cstdio> (802)#include<iostream> using namespace std; int main() { int ping[13] = {0,31,28,31,30,31,30,31,31,30,31,30,31}; int run[13] = {0,31,29,31,30,31,30,31,31,30,31,30,31}; int year; int month; int day; while(cin>>year>>month) { if(year%400==0||year%4==0&&year%100!=0) { day = run[month]; cout<<day<<endl; } else { day = ping[month]; cout<<day<<endl; } } return 0; }
#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 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) ) { int day = days[m - 1]; if ((y % 4 == 0 && y % 100 != 0) || (y % 400 == 0)) { if (m == 2) day++; } printf("%d\n", day); } return 0; }