当前位置:网站首页>[PTA] get rid of singles

[PTA] get rid of singles

2022-04-23 20:22:00 Maybe

subject

 Insert picture description here

Their thinking

Imitation Division
1. Accumulate first 1, Until it's bigger than the divisor ( Now you can divide by the divisor )
2. Get the result of division and the remainder of division , Output the result of dividing by
3. Move backward , Fill a
4. repeat 2、3, until 2 The remainder is 0 Stop when

ac Code

#include<iostream>
using namespace std;
int main() {
    
	int n, k = 1, cnt = 1;
	cin >> n;
	while(k < n) {
    
		k = k * 10 + 1;
		cnt++;
	}
	while(1) {
    
		if(k % n == 0) {
    
			cout << k / n << cnt;
			break;
		} else {
    
			cout << k / n;
            k %= n;
			k = k * 10 + 1;
			cnt++;
		}
	}
	return 0;
}

版权声明
本文为[Maybe]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204232020000426.html

随机推荐