开始忘记转换str-‘0’了
改之后居然直接出了结果——235
是我没想到的 嘻嘻(希望明天也有这样的好运)
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;
const int months[]={0,31,28,31,30,31,30,31,31,30,31,30,31};
const int number[]={5, 6, 8, 6, 9, 1, 6, 1, 2, 4,
9, 1, 9, 8, 2, 3, 6, 4, 7, 7,
5, 9, 5, 0, 3, 8, 7, 5, 8, 1,
5, 8, 6, 1, 8, 3, 0, 3, 7, 9,
2, 7, 0, 5, 8, 8, 5, 7, 0, 9,
9, 1, 9, 4, 4, 6, 8, 6, 3, 3,
8, 5, 1, 6, 3, 4, 6, 7, 0, 7,
8, 2, 7, 6, 8, 9, 5, 6, 5, 6,
1, 4, 0, 1, 0, 0, 9, 4, 8, 0,
9, 1, 2, 8, 5, 0, 2, 5, 3, 3};
int is_leap(int year){
if(year%4==0&&year%100||year%400==0) return 1;
return 0;
}
int get_days(int year,int month){
if(month==2) return 28+is_leap(year);
return months[month];
}
bool check(int y,int m,int d){
if(m<0||m>12) return false;
if(d<0) return false;
if(d>get_days(y,m)) return false;
return true;
}
int main(){
char str[8];
int res=0;
for(int m=1;m<=12;m++){
for(int d=1;d<=31;d++){
if(check(2023,m,d)){
sprintf(str,"%04d%02d%02d",2023,m,d);
for(int i=0,k=0;k<8&&i<100;i++){
if(number[i]==str[k]-'0') k++ ;
if(k==8){
res++;
continue;
}
}
}
}
}
cout<<res<<endl;
return 0;
}