aboutsummaryrefslogtreecommitdiff
path: root/tests/sysy_lvX/078_int_io.sy
diff options
context:
space:
mode:
authorRichard Qin <richard.qin.001@gmail.com>2026-09-15 08:16:43 +0800
committerRichard Qin <richard.qin.001@gmail.com>2026-09-15 08:16:43 +0800
commit4022e5c95210631e4aceb08eaf9d9071aa5aefc4 (patch)
treea5922559836e45fb3459a3d070367912e1035b1a /tests/sysy_lvX/078_int_io.sy
downloadrcc-master.tar.gz
rcc-master.tar.xz
Set up a git repoHEADmaster
Diffstat (limited to 'tests/sysy_lvX/078_int_io.sy')
-rw-r--r--tests/sysy_lvX/078_int_io.sy52
1 files changed, 52 insertions, 0 deletions
diff --git a/tests/sysy_lvX/078_int_io.sy b/tests/sysy_lvX/078_int_io.sy
new file mode 100644
index 0000000..4f1b992
--- /dev/null
+++ b/tests/sysy_lvX/078_int_io.sy
@@ -0,0 +1,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;
+}