统计一下 aaa ⋯ aaan个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 <cstring> using namespace std; int count[10]; int main(int argc, const char * argv[]) { int T; cin >> T; int a, b, d, n; int temp, v; for (int i = 0; i < T; i++) { memset(count, 0, sizeof(count)); cin >> a >> b >> d >> n; int c = 0; for (int j = 0; j < n; j++) { temp = a * b + c; c = temp / 10; v = temp % 10; if (count[v]) { count[v] += n - j; break; } else { count[v]++; } } if (c > 0) { count[c]++; } cout << count[d] << endl; } return 0; }