题目地址:https://www.nowcoder.com/pat/6/problem/4043
题解:遍历大数,边除边输出,最后得到余数输出即可
1 /**
2 *
3 *作者:Ycute
4 *时间:2019-11-14-19.31.22
5 *题目题解简单描述:遍历相除就好了
6 */
7
8
9 #include<iostream>
10 #include<cmath>
11 #include<cstring>
12 #include<algorithm>
13 #include<vector>
14 using namespace std;
15
16
17 int main(){
18 char ch[1005];
19 int chushu;
20 scanf("%s %d",ch,&chushu);
21 int l=strlen(ch);
22 int yushu=0;
23 int temp=ch[0]-'0';
24 if(temp/chushu)printf("%d",temp/chushu);//处理下第一个数,为0时不输出
25 yushu=temp%chushu;
26 for(int i=1;i<l;i++){
27 temp=ch[i]-'0';
28 temp=yushu*10+temp;
29 printf("%d",temp/chushu);
30 yushu=temp%chushu;
31 }
32 printf(" %d",yushu);
33 return 0;
34 }