日历中的数字(牛客日期技巧\sprintf)
#include <bits/stdc++.h>
using namespace std;
int month[13] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
signed main(){
int y, m, x;
while(cin >> y >> m >> x){
int res = 0;
if(y % 4 == 0 && y % 100 != 0 || y % 400 == 0) month[2] = 29;
else month[2] = 28;
for(int i = 1; i <= month[m]; ++i){
char s[10];
sprintf(s, "%04d%02d%02d", y, m, i);
res += count(s, s + 8, char(x + '0'));
}
cout << res << endl;
}
return 0;
}

浙公网安备 33010602011771号