问题描述
解决方案
#include <stdio.h>int mt[13] = { 0 31 28 31 30 31 30 31 31 30 31 30 31 };void set2(int y){ if (y % 4 != 0) { mt[2] = 28; } else { if (y % 100 == 0 && y % 400 != 0) mt[2] = 28; else mt[2] = 29; }}void showmenu(){ printf(""1. y/n/d -> ydn""); printf(""2. yd -> y/n/dn""); printf(""3. exitn""); }int ymd2yd(int y int m int d){ set2(y); int r = 0; for (int i = 0; i < m; i++) r += mt[i]; r += d; return r;}void yd2ymd(int yd int * r){ set2(r[0]); int m = 0; while (yd > mt[m]) { yd -= mt[m++]; } r[1] = m; r[2] = yd;}int main(){ char c; showmenu(); while (scanf(""%c"" &c) 1) { switch (c) { case '1': int y int m int d; scanf(""%d"" &y); scanf(""%d"" &m); scanf(""%d"" &d); printf(""%dn"" ymd2yd(y m d)); showmenu(); break; case '2': int yd; int r[3]; scanf(""%d"" &r[0]); scanf(""%d"" &yd); yd2ymd(yd r); printf(""%d %d %dn"" r[0] r[1] r[2]); showmenu(); break; case 'n': break; default: return 0; } } return 0;}
解决方案二:
- y/n/d -> yd
- yd -> y/n/d
- exit 12016 3 161
- y/n/d -> yd
- yd -> y/n/d
- exit 12016 7 18200
- y/n/d -> yd
- yd -> y/n/d
- exit 12015 12 31365
- y/n/d -> yd
- yd -> y/n/d
- exit 22016 612016 3 1
- y/n/d -> yd
- yd -> y/n/d
- exit 22015 612015 3 2
- y/n/d -> yd
- yd -> y/n/d
- exit 22015 2252015 8 13
- y/n/d -> yd
- yd -> y/n/d
- exit 3Press any key to continue
解决方案三:
1. y/n/d -> yd2. yd -> y/n/d3. exit 12016 3 11. y/n/d -> yd2. yd -> y/n/d3. exit 12016 7 181. y/n/d -> yd2. yd -> y/n/d3. exit 12015 12 311. y/n/d -> yd2. yd -> y/n/d3. exit 22016 612016 3 11. y/n/d -> yd2. yd -> y/n/d3. exit 22015 612015 3 21. y/n/d -> yd2. yd -> y/n/d3. exit 22015 2252015 8 131. y/n/d -> yd2. yd -> y/n/d3. exit 3Press any key to continue
时间: 2024-11-05 16:37:51