-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path10494.cpp
More file actions
47 lines (44 loc) · 958 Bytes
/
10494.cpp
File metadata and controls
47 lines (44 loc) · 958 Bytes
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
#include <bits/stdc++.h>
long long div(char a[], long long n, char c[]) {
int i, j, t = 0, l, d = 0, r = -1;
long long rem = 0;
l = strlen(a);
for (i = 0; i < l; i++) {
rem = (rem * 10) + a[i] - 48;
if (r >= 0) {
r++;
}
if (rem >= n) {
j = rem / n;
rem = rem % n;
c[d] = j + 48;
d++;
t = 1;
r = 0;
} else if (rem < n && r > 0) {
c[d] = '0';
d++;
}
}
if (d == 0) {
c[d] = '0';
d++;
}
c[d] = '\0';
return rem;
}
int main() {
long long n;
char a[100000], c[100000];
char ch;
while (scanf("%s %c %lld", &a, &ch, &n) != EOF) {
if (ch == '%') {
n = div(a, n, c);
printf("%lld\n", n);
} else if (ch == '/') {
div(a, n, c);
printf("%s\n", c);
}
}
return 0;
}