http://acm.hdu.edu.cn/showproblem.php?pid=2005
1 #include<iostream> 2 #include<stdio.h> 3 #include<math.h> 4 #include<queue> 5 #include<stack> 6 #include<algorithm> 7 #define PI 3.1415927 8 using namespace std; 9 10 int main() 11 { 12 int a,b,c,i; 13 int x[15]={31,28,31,30,31,30,31,31,30,31,30,31}; 14 int y[15]={31,29,31,30,31,30,31,31,30,31,30,31}; 15 while(~scanf("%d/%d/%d",&a,&b,&c)) 16 { 17 int sum=0; 18 if((a%100!=0&&a%4==0)||(a%400==0)) 19 { 20 for(i=0;i<b-1;i++) 21 { 22 sum+=y[i]; 23 } 24 sum+=c; 25 printf("%d\n",sum); 26 } 27 else 28 { 29 for(i=0;i<b-1;i++) 30 { 31 sum+=x[i]; 32 } 33 sum+=c; 34 printf("%d\n",sum); 35 } 36 37 } 38 return 0; 39 }
暴力方法
1 #include<iostream> 2 #include<stdio.h> 3 #include<math.h> 4 #include<queue> 5 #include<stack> 6 #include<algorithm> 7 #define PI 3.1415927 8 using namespace std; 9 10 int main() 11 { 12 int a,b,c; 13 while(~scanf("%d/%d/%d",&a,&b,&c)) 14 { 15 if((a%100!=0&&a%4==0)||a%400==0) 16 { 17 if(b<2) 18 { 19 printf("%d\n",c); 20 } 21 else if (b==2) 22 { 23 printf("%d\n",31+c); 24 } 25 else if (b==3) 26 { 27 printf("%d\n",60+c); 28 } 29 else if (b==4) 30 { 31 printf("%d\n",91+c); 32 } 33 else if (b==5) 34 { 35 printf("%d\n",121+c); 36 } 37 else if (b==6) 38 { 39 printf("%d\n",152+c); 40 } 41 else if (b==7) 42 { 43 printf("%d\n",182+c); 44 } 45 else if (b==8) 46 { 47 printf("%d\n",213+c); 48 } 49 else if (b==9) 50 { 51 printf("%d\n",244+c); 52 } 53 else if (b==10) 54 { 55 printf("%d\n",274+c); 56 } 57 else if (b==11) 58 { 59 printf("%d\n",305+c); 60 } 61 else 62 { 63 printf("%d\n",335+c); 64 } 65 } 66 else 67 { 68 if(b<2) 69 { 70 printf("%d\n",c); 71 } 72 else if (b==2) 73 { 74 printf("%d\n",31+c); 75 } 76 else if (b==3) 77 { 78 printf("%d\n",59+c); 79 } 80 else if (b==4) 81 { 82 printf("%d\n",90+c); 83 } 84 else if (b==5) 85 { 86 printf("%d\n",120+c); 87 } 88 else if (b==6) 89 { 90 printf("%d\n",151+c); 91 } 92 else if (b==7) 93 { 94 printf("%d\n",181+c); 95 } 96 else if (b==8) 97 { 98 printf("%d\n",212+c); 99 } 100 else if (b==9) 101 { 102 printf("%d\n",243+c); 103 } 104 else if (b==10) 105 { 106 printf("%d\n",273+c); 107 } 108 else if (b==11) 109 { 110 printf("%d\n",304+c); 111 } 112 else 113 { 114 printf("%d\n",334+c); 115 } 116 } 117 118 } 119 120 return 0; 121 }
时间: 2024-10-28 10:59:17