-
Notifications
You must be signed in to change notification settings - Fork 0
/
B1017.cpp
57 lines (51 loc) · 874 Bytes
/
B1017.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#include <cstdio>
#include <cstring>
int maxn = 1001;
struct begin{
int d[maxn];
int len;
begin(){//begin 的构造函数 也就是一个初始化函数
memset(d, 0, sizeof(d));
len = 0;
}
};
bign change (char str[]){//字符串数组变成int数组
bign a;
a.len = strlen(str);
for(int i = 0; i < a.len; i++){
a.d[i] = str[a.len - i- 1] - '0';
}
return a;
}
int divide(begin a, int b){
bign c;
int r = 0;
c.len = a.len;
for(int i = a.len - 1; i >= 0; i--){
r = r * 10 + a.d[i];
if(r < b)
c.d[i] = 0;
else{
c.d[i] = r / d;
r = r % d;
}
}
while(c.len - 1 >= 1 && c.d[c.len - 1] == 0){
c.len--;
}
for(int i = 0; i < c.len; i++){
printf("%d", c.d[i]);
}
printf(" ");
return r;
}
int main()
{
char a[maxn];
int b;
scanf("%s %d", &a, &b);
begin a1= change(a);
int c = divide(a1, b);
printf("%d\n", c);
return 0;
}