-
Notifications
You must be signed in to change notification settings - Fork 2
/
B1017.cpp
50 lines (46 loc) · 831 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
#include <cstdio>
#include <cstring>
using namespace std;
struct BigInt{
int digit[1010], len;
BigInt() : len(0) {
memset(digit, 0, sizeof(digit));
}
} q, a;
BigInt transfer(char str[]){
BigInt c;
c.len = strlen(str);
for(int i = 0; i < c.len; ++i){
c.digit[i] = str[c.len - i - 1] - '0';
}
return c;
}
BigInt divide(const BigInt &a, int b, int &r){
BigInt c;
c.len = a.len;
for(int i = c.len - 1; i >= 0; --i){
r = r * 10 + a.digit[i];
if(r < b){
c.digit[i] = 0;
}else{
c.digit[i] = r / b;
r %= b;
}
}
while(c.len - 1 >= 1 && c.digit[c.len - 1] == 0){
--c.len;
}
return c;
}
int main(){
char str[1010];
int b, r = 0;
scanf("%s%d", str, &b);
a = transfer(str);
q = divide(a, b, r);
for(int i = q.len - 1; i >= 0; --i){
printf("%d", q.digit[i]);
}
printf(" %d\n", r);
return 0;
}