B - Position in Fraction

Examples
Input
1 2 0
Output
2
Input
2 3 7
Output
-1

题意:a/b 1/2=0.500  c= 0 0是小数点后第二位数字 输出2


模拟出发过程,先乘以10,除,然后用余数除


#include<iostream>
#include<cstdio>
#define n 1e5+10
using namespace std;
int main(){
	int a,b,c,ans;
	while(cin>>a>>b>>c){
		ans=-1;
		for(int i=1;i<n;i++){
			a*=10;
			if(a/b==c){
				ans=i;
				break;
				
		}
		a%=b;
		
	}cout<<ans<<endl;
	return 0;
} 
}

猜你喜欢

转载自blog.csdn.net/dujuancao11/article/details/79902779