統計一下 aaa ⋯ aaan個a × b 的結果裏面有多少個數字d,a,b,d均爲一位數。
樣例解釋:
3333333333*3=9999999999,裏面有10個9。
多組測試數據。 第一行有一個整數T,表示測試數據的數目。(1≤T≤5000) 接下來有T行,每一行表示一組測試數據,有4個整數a,b,d,n。 (1≤a,b≤9,0≤d≤9,1≤n≤10^9)
對於每一組數據,輸出一個整數佔一行,表示答案。
2 3 3 9 10 3 3 0 10
10 0
代碼:
#include<algorithm>
#include<iostream>
#include<string.h>
#include<stdio.h>
#include<math.h>
#include<vector>
#include<map>
typedef long long ll;
using namespace std;
const int N=1e6+10;
int main()
{
int t,a,b,d,n;
cin>>t;
while(t--)
{
cin>>a>>b>>d>>n;
if(a*b<10)
{
if(d==a*b)
cout<<n<<endl;
else
cout<<0<<endl;
}
else
{
int r=(a*b)%10;
int z=(a*b)/10;//表示進位
int s[10];
memset(s,0,sizeof(s));
s[r]++;
n--;//處理完最右邊的一位數字,n減一
while(n)
{
r=(a*b+z)%10;
z=(a*b+z)/10;//表示最左邊的一位數
if(s[r])
{
s[r]+=n;
break;
}
else
s[r]++;
n--;
}
s[z]++;
cout<<s[d]<<endl;
}
}
}