关于#2

P5690 [CSP-S2019 江西] 日期

@[中二少年C_T_Lin](/user/191248) 当 `mm` 个位为0时 `mmm` =0 则 `mmm`-1 就炸了 建议加一个特判应该能过
by Lazy_Labs @ 2021-07-28 19:30:49


@[中二少年C_T_Lin](/user/191248) AC code: ```cpp #include <iostream> #include <cstring> using namespace std; const string Date[12]=\ {"31", "28", "31", "30", "31", "30", "31", "31", "30", "31", "30", "31"}; const string Month[12]=\ {"01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12"}; string s, m, d; int mm, dd, tot, tot1, tot2, tot3; int main( ) { cin >> s; m = s.substr(0,2); d = s.substr(3,2); mm = (s[0] - '0') * 10 + (s[1] - '0'); dd = (s[3] - '0') * 10 + (s[4] - '0'); if(mm > 0 && mm < 13) { tot = 0; if(Date[mm - 1][0] < d[0] || (Date[mm - 1][0] >= d[0] && Date[mm - 1][1] < d[1])) { tot++; } cout << tot; } else if(mm > 0&& mm % 10 != 0){//加一句mm%10!=0即可 tot1 = 1; int mmm = mm % 10; if(Date[mmm - 1][0] < d[0] || (Date[mmm - 1][0] >= d[0] && Date[mmm - 1][1] < d[1]) || dd == 0) { tot1++; } tot2 = 0x3f3f3f; if(mm % 10 < 3) { tot2 = 1; int mmm = mm % 10 + 10; if(Date[mmm - 1][0] < d[0] || (Date[mmm - 1][0] >= d[0] && Date[mmm - 1][1] < d[1]) || dd == 0) { tot2++; } } cout << min(tot1, tot2); } else { tot1 = 1; int mmm = 1; if(Date[mmm - 1][0] < d[0] || (Date[mmm - 1][0] >= d[0] && Date[mmm - 1][1] < d[1]) || dd == 0) { tot1++; } tot2 = 1; mmm = 2; if(Date[mmm - 1][0] < d[0] || (Date[mmm - 1][0] >= d[0] && Date[mmm - 1][1] < d[1]) || dd == 0) { tot2++; } tot3 = 1; mmm = 4; if(Date[mmm - 1][0] < d[0] || (Date[mmm - 1][0] >= d[0] && Date[mmm - 1][1] < d[1]) || dd == 0) { tot3++; } cout << min(tot1, min(tot2, tot3)); } } ```
by Lazy_Labs @ 2021-07-28 19:33:25


@[中二少年C_T_Lin](/user/191248) 不介意的话点个关注 I AK IOI!
by Lazy_Labs @ 2021-07-28 19:34:14


@[a929666](/user/376137) 谢谢,已AC+关注
by Genshineer @ 2021-07-29 16:41:43


@[中二少年C_T_Lin](/user/191248) ???????????????????? 有人JC我????????????????
by Lazy_Labs @ 2021-07-29 18:49:26


|