模拟竖式除法。最好在纸上写一写,111/13,1111/13,1111/13。每次结果的余数后面加一个1就相当于是在被除数后面加了一个1.
还有,a数组要开的足够大。
#include <bits/stdc++.h>
using namespace std;
int main(){
int n,single =1;
cin>>n;
int cnt=1;//1有多少位
while(single<n){
single=single*10+1;
cnt++;
}
int a[100],rest;//最终的结果
int idx=0;
a[idx++]=single/n;
rest=single%n;
while(true){
//是否能够整除
if(rest==0) break;
single=rest*10+1;
cnt++;
a[idx++]=single/n;
rest=single%n;
}
for(int i=0;i<idx;i++){
cout<<a[i];
if(i==idx-1) cout<<" ";
}
cout << cnt<<'\n';
return 0;
}
标签:13,int,1111,single,L1,046,整除
From: https://www.cnblogs.com/chengyiyuki/p/18069095