51nod 数数字(水题)

题目链接:

数数字

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

统计一下 aaa  aana × 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

题意:


思路:

可以发现最后得出的结果一般都是第一个数和最后两个数不同,中间的都相同;


AC代码:

//#include <bits/stdc++.h>
#include <iostream>
#include <queue>
#include <cmath>
#include <map>
#include <cstring>
#include <algorithm>
#include <cstdio>
using namespace std;
#define Riep(n) for(int i=1;i<=n;i++)
#define Riop(n) for(int i=0;i<n;i++)
#define Rjep(n) for(int j=1;j<=n;j++)
#define Rjop(n) for(int j=0;j<n;j++)
#define mst(ss,b) memset(ss,b,sizeof(ss));
typedef long long LL;
const LL mod=1e9+7;
const double PI=acos(-1.0);
const int inf=0x3f3f3f3f;
const int N=1e5+25;
int flag[12];
int main()
{
        int t;
        scanf("%d",&t);
        while(t--)
        {
            int a,b,c,n;
            mst(flag,0);
            scanf("%d%d%d%d",&a,&b,&c,&n);
            if(a*b<10)
            {
                flag[a*b]=n;
            }
            else
            {
                if(n==1)
                {
                    int x=a*b/10,y=a*b%10;
                    flag[y]++;
                    flag[x]++;
                }
                else
                {
                    int x=a*b/10,y=a*b%10;
                    flag[y]++;
                    flag[(x+y)%10]++;
                    flag[(x+y+(x+y)/10)%10]+=(n-2);
                    flag[x+(x+y+(x+y)/10)/10]++;
                }
                }
            printf("%d
",flag[c]);

        }
    return 0;
}
原文地址:https://www.cnblogs.com/zhangchengc919/p/5515470.html