-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.txt
57 lines (51 loc) · 1.03 KB
/
test.txt
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
fn itoch(i: int) -> int {
if i < 10 {
return '0' + i;
} else {
return 'a' + i - 10;
}
}
fn modulo(a: int, b: int) -> int {
return a - a/b*b;
}
fn div_modulo(x: int, div_cnt: int, rhs: int) -> int {
while div_cnt > 0 {
x = x / rhs;
div_cnt = div_cnt - 1;
}
return modulo(x, rhs);
}
fn itoa(i: int, const radix: int) -> void {
let char_count: int = 0;
let ij: int;
if i < 0 {
i = -i;
putchar('-');
}
ij = i;
if ij == 0 {
char_count = 1;
} else {
while ij > 0 {
ij = ij / radix;
char_count = char_count + 1;
}
}
while char_count > 0 {
char_count = char_count - 1;
putchar(itoch(div_modulo(i, char_count, radix)));
}
}
fn main() -> void {
let count: int;
let radix: int;
let number: int;
count = getint();
while count > 0 {
number = getint();
radix = getint();
itoa(number, radix);
putln();
count = count - 1;
}
}