求
除了#1其他都过了,求大佬们帮我看下是哪里出的问题
#include <bits/stdc++.h>
using namespace std;
#define sqrt __builtin_sqrtf //使用硬件加速的开方
#ifdef ONLINE_JUDGE
#define getchar getchar_unlocked
#endif
inline void read() {}
template <typename T, typename... R>
inline void read(T &x,R &... oth){
x=0;T f=1;
char c=getchar();
while(c<'0' || c>'9') {
if(c=='-') f=-1;
c=getchar();
}
while(c>='0' && c<='9') x=(x<<1)+(x<<3)+(c&15),c=getchar();
x*=f;
read(oth...);
return;
}
int T;
string s;
int a[10];
int ans;
bool hnone;
void init(){
hnone=false;
ans=0;
memset(a,0,sizeof(a));
}
bool isp(int num){
if (num==1) return false;
if (num==2) return true;
for (int i=2;i*i<=num;i++)
if (num%i==0) return false;
return true;
}
int Day[]={0,31,28,31,30,31,30,31,31,30,31,30,31};
bool alive(){
int month=a[5]*10+a[6],day=a[7]*10+a[8],
year=a[1]*1000+a[2]*100+a[3]*10+a[4];
if (year<1 || year>9999) return false;
if (month<1 || month>12) return false;
if (day<1) return false;
if (month==2){
if ((year%4==0 && year%100!=0) || year%400==0) {
if (day>29) return false;
}else if (day>28) return false;
}else if (Day[month]<day) return false;
return true;
}
bool check(){
if (!alive()) return false;
//printf("\ninput check\n");
int month=a[5]*10+a[6],day=a[7]*10+a[8],
year=a[1]*1000+a[2]*100+a[3]*10+a[4];
return isp(day) && isp(month*100+day)
&& isp(year*10000+month*100+day);
}
void dfs(int now){
if (now>8) {
//output();
if (check()) ans++;
return;
}
if (a[now]!=-1) dfs(now+1);
else{
for (int i=0;i<=9;i++){
a[now]=i;
dfs(now+1);
}
a[now]=-1;
}
return;
}
signed main(){
read(T);
for (int z=1;z<=T;z++){
init();
cin>>s;
if (s=="--------"){
printf("55157\n");
continue;
}
for (int i=0;i<8;i++){
if (s[i]=='-') a[i+1]=-1,hnone=true;
else a[i+1]=(s[i]-'0');
}
if (!hnone){
printf("0\n");
continue;
}
dfs(1);
printf("%d\n",ans);
}
return 0;
}