-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path10494-2.cpp
More file actions
41 lines (38 loc) · 840 Bytes
/
Copy path10494-2.cpp
File metadata and controls
41 lines (38 loc) · 840 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
#include <bits/stdc++.h>
using namespace std;
long long div(char a[], long long n, char c[]) {
int i, j, t = 0, l, d = 0, r = 0;
long long rem = 0;
l = strlen(a);
for (i = 0; i < l; i++) {
rem = (rem * 10) + a[i] - 48;
if (rem >= n || r != 0) {
j = rem / n;
rem = rem % n;
c[d] = j + 48;
d++;
r = 1;
}
}
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;
}