aboutsummaryrefslogtreecommitdiff
path: root/tests/sysy_lvX/078_int_io.sy
blob: 4f1b9926f50ace1163c21a47ad2bc3a8de716f1e (plain)
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
const int ascii_0 = 48;

int my_getint()
{
    int sum = 0, c;

    while (1) {
        c = getch() - ascii_0;
        if (c < 0 || c > 9) {
            continue;
        } else {
            break;
        }
    }
    sum = c;

    while (1) {
        c = getch() - ascii_0;
        if (c >= 0 && c <= 9) {
            sum = sum * 10 + c;
        } else {
            break;
        }
    }

    return sum;
}

void my_putint(int a)
{
    int b[16], i = 0;
    while (a > 0) {
        b[i] = a % 10 + ascii_0;
        a = a / 10;
        i = i + 1;
    }
    while (i > 0) {
        i = i - 1;
        putch(b[i]);
    }
}

int main()
{
    int n = my_getint();
    while (n > 0) {
        int m = my_getint();
        my_putint(m); putch(10);
        n = n - 1;
    }
    return 0;
}