zhn0707 @ 2020-05-06 20:55:10
啥玩意?话说我这个是不是有点复杂?
#include<iostream>
#include<cstring>
#include<cstdio>
#include<sstream>
using namespace std;
string tostring(int &i){
string s;
stringstream ss(s);
ss<<i;
return ss.str();
}
string ca(string a1,string b1){
string c1;
int a[1001]={},b[1001]={},c[1001]={},lena,lenb,lenc,x;
lena=a1.length();lenb=b1.length();
for(int i=0;i<lena;i++)a[lena-i]=a1[i]-48;
for(int i=0;i<lenb;i++)b[lenb-i]=b1[i]-48;
for(int i=1;i<=lena;i++){
x=0;
for(int j=1;j<=lenb;j++){
c[i+j-1]=a[i]*b[j]+x+c[i+j-1];
x=c[i+j-1]/10;
c[i+j-1]%=10;
}
c[i+lenb]=x;
}
lenc=lena+lenb;
while(c[lenc]==0&&lenc>1)lenc--;
for(int i=1;i<=lenc;i++){
int &temp=c[lenc-i+1];
c1+=tostring(temp);
}
return c1;
}
string jie(int n){
string s="1";
if(n==1)return "1";
for(int i=2;i<=n;i++){
stringstream ss;
ss<<i;
string ii=ss.str();
s=ca(s,ii);
}
return s;
}
int main(){
int t,n,a;
cin>>t;
for(int i=1;i<=t;i++){
int sum=0;
cin>>n>>a;
string s=jie(n);
for(int j=0;j<s.length();j++){
if(s[j]==char(a+48))sum++;
}
cout<<sum<<endl;
}
}
by zhn0707 @ 2020-05-06 21:19:22
@Preon ???
by _Legacy @ 2020-05-06 21:30:30
检查一下初始化,我也想不出其他可能了。
by _Legacy @ 2020-05-06 21:30:48
干脆自己做一下