您的位置:首页 > 其它

BSG白山极客挑战赛

2016-05-21 10:59 197 查看
数数字

System Message (命题人) yule_z (测试)

基准时间限制:1 秒 空间限制:262144 KB 分值: 20

统计一下 aaa ⋯ aaan个a × b 的结果里面有多少个数字d,a,b,d均为一位数。

样例解释:

3333333333*3=9999999999,里面有10个9。

Input

多组测试数据。

第一行有一个整数T,表示测试数据的数目。(1≤T≤5000)

接下来有T行,每一行表示一组测试数据,有4个整数a,b,d,n。 (1≤a,b≤9,0≤d≤9,1≤n≤10^9)

Output

对于每一组数据,输出一个整数占一行,表示答案。

Input示例

2

3 3 9 10

3 3 0 10

Output示例

10

0

找规律

代码:

#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <string>

using namespace std;
const int maxx=105;
int m[maxx];
int main()
{
int a,b,d,n;
int t;
scanf("%d",&t);
while(t--)
{
scanf("%d%d%d%d",&a,&b,&d,&n);
memset(m,0,sizeof(m));
int x,y,y1,y2,y3;
if(n==1) ///如果只有一个的情况下直接乘,然后存储
{
x=a*b;
if(x>=10)
{
y=x%10;
m[y]++;
y1=x/10;
m[y1]++;
}
else
m[x]++;
}

else
{
x=a*b;
if(x>=10)
{
y=x%10;
m[y]++;
y1=x/10;
y2=y1+x;
if(y2/10>y1%10)///有些特殊的数据(例如7777*7或者8888*6~~~~~~)
{
y3=y2%10;
m[y3]++;
y1=y2/10;
y2=y1+x;
y3=y2%10;
m[y3]=n-2;
}
else
{

y3=y2%10;
m[y3]=n-1;

}
int y4=y2/10;
m[y4]++;

}
else
m[x]=n;
}
printf("%d\n",m[d]);

}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: