51nod1770(xjb)

题目链接:http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1770

题意:中文题诶~

思路:随便写几个例子不难发现乘机中间部分会出现循环,只需考虑3个a的情况即可。。。

代码:

 1 #include <iostream>
 2 using namespace std;
 3 
 4 int main(void){
 5    int t, a, b, d, n;
 6    cin >> t;
 7    while(t--){
 8        cin >> a >> b >> d >> n;
 9        int cnt=0, ans=0;
10        if(n<3){
11            for(int i=1; i<=n; i++){
12                cnt=cnt*10+a;
13            }
14            cnt=cnt*b;
15            while(cnt){
16                int cc=cnt%10;
17                if(cc==d) ans++;
18                cnt/=10;
19            }
20        }else{
21            for(int i=1; i<=3; i++){
22                cnt=cnt*10+a;
23            }
24            cnt=cnt*b;
25            while(cnt){
26                int cc=cnt%10;
27                if(cc==d){
28                    if(cnt/10!=0&&cnt/100==0) ans+=n-2;
29                    else ans+=1;
30                }
31                cnt/=10;
32            }
33        }
34        cout << ans << endl;
35    }
36    return 0;
37 }
View Code
原文地址:https://www.cnblogs.com/geloutingyu/p/6748903.html