1770 数数字

来源:互联网 发布:网络攻防实验室 编辑:程序博客网 时间:2024/05/03 01:26

分两种情况1:a*b<=9   所有相乘的情况是相同的  2:a*b>9   循环找到第一个相同的数字  

#include<iostream>#include<cstdio>#include<cstring>using namespace std;int main(){int T;scanf("%d",&T);while(T--){int a,b,d,n;int ans=0,c=0,cnt=0;scanf("%d%d%d%d",&a,&b,&d,&n);if(a*b<=9){if(a*b==d){printf("%d\n",n);}else{printf("0\n");}}else{int temp1=(a*b)%10;int temp2=(a*b)/10;//进位 int ans[10]={0};ans[temp1]++;n--;while(n){temp1=(a*b+temp2)%10;temp2=(a*b+temp2)/10;if(ans[temp1]){ans[temp1]+=n;break;}else{ans[temp1]++;}n--;}ans[temp2]++;printf("%d\n",ans[d]);}}return 0;}


0 0