打表
要注意不到7月前和8月后的情况
同时注意“0号”等特殊情况
1 #include <cstdio> 2 #include <algorithm> 3 #include <cstring> 4 using namespace std; 5 6 #define REP(n) for(int o=0;o<n;o++) 7 8 //bool first = true; 9 int main() { 10 bool a[2][32];//是否停电 11 memset(a, 0, sizeof(a)); 12 13 //停电日期打表 14 int i = 1; 15 bool *it = &a[0][1]; 16 bool first_8 = true; 17 while (1) { 18 if (it > &a[1][31]) 19 break; 20 if (it >= &a[1][0] && first_8 == true) { 21 first_8 = false; 22 it++; 23 } 24 *it = true; 25 it += ++i; 26 } 27 28 //日历输出调试 29 /** 30 for (int i = 0; i < 2; i++) { 31 printf("%d ", i + 7); 32 for (int j = 1; j < 32; j++) { 33 printf("%3d(%d) ", j, a[i][j]); 34 if (j % 7 == 0)printf(" "); 35 } 36 printf(" "); 37 } 38 /**/ 39 40 //输出 41 int m, d; 42 scanf("%d/%d", &m, &d); 43 while (m != 0 && d != 0) { 44 /* 45 if (!first) 46 printf(" "); 47 first = false; 48 */ 49 50 //月份不在7、8月 51 if (m < 7) { 52 printf("10 "); 53 scanf("%d/%d", &m, &d); 54 continue; 55 } 56 if (m > 8) { 57 printf("0 "); 58 scanf("%d/%d", &m, &d); 59 continue; 60 } 61 62 int cnt = 0; 63 for (bool *i = &a[m - 7][d]; i <= &a[1][31]; i++) { 64 if (i == &a[1][0]) 65 continue; 66 if (*i == true) 67 cnt++; 68 } 69 printf("%d ", cnt); 70 scanf("%d/%d", &m, &d); 71 } 72 73 return 0; 74 }