日历中的数字(牛客日期技巧\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;
}
posted @ 2025-03-17 20:39  awei040519  阅读(17)  评论(0)    收藏  举报