0pts,样例都不过?请各位帮忙看看。
代码如下:经个人检验,HPmLP()和Fac()均没有问题,问题大致出在统计字符那块。
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <cstdlib>
#include <cctype>
#include <cmath>
#include <algorithm>
#include <stack>
#include <queue>
#include <utility>
#include <map>
#include <set>
#include <list>
#include <vector>
using namespace std;
const int maxn=20005;
string HPmLP(string h,int l)//高精度乘单精度
{
string r;
int a[maxn]={0},len=h.size();
for(int i=0; i<h.size(); ++i) {
a[i]=h[h.size()-1-i]-48;
}
for(int i=0; i<h.size(); ++i) {
a[i]*=l;
}
for(int i=0; i<h.size(); ++i) {
a[i+1]+=a[i]/10;
a[i]%=10;
}
while(a[len]!=0) {
++len;
a[len]+=a[len-1]/10;
a[len-1]%=10;
}
while(len>1&&a[len-1]==0) {
--len;
}
for(int i=0; i<len; ++i) {
r=(char)(a[i]+'0')+r;
}
return r;
}
string Fac(int n)//计算n 的阶乘,返回string
{
string r="1";
if(n==0||n==1) {
return "1";
}
for(int i=n; i>=2; --i) {
r=HPmLP(r,i);
}
return r;
}
int main()
{
int n,t,a;
char c;
long long sum;
scanf("%d",&t);
while(t--) {//循环t次
scanf("%d%d",&n,&a);
c=(char)(a+'0');
string s=Fac(n);//s存储阶乘
int pos=s.find(c);//用find查找数码
sum=0;
while(pos!=-1) {
++sum;
pos=s.find(pos+1,c);
}
printf("%d\n",sum);
}
return 0;
}