forked from NUDT-compiler/nudt-compiler-cpp
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
81 lines
1.3 KiB
81 lines
1.3 KiB
#include "sylib.h"
|
|
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
|
|
static int read_char_normalized(void) {
|
|
int ch = getchar();
|
|
if (ch == '\r') {
|
|
int next = getchar();
|
|
if (next != '\n' && next != EOF) {
|
|
ungetc(next, stdin);
|
|
}
|
|
return '\n';
|
|
}
|
|
return ch;
|
|
}
|
|
|
|
static float read_float_token(void) {
|
|
char buffer[256];
|
|
if (scanf("%255s", buffer) != 1) {
|
|
return 0.0f;
|
|
}
|
|
return strtof(buffer, NULL);
|
|
}
|
|
|
|
int getint(void) {
|
|
int value = 0;
|
|
if (scanf("%d", &value) != 1) {
|
|
return 0;
|
|
}
|
|
return value;
|
|
}
|
|
|
|
int getch(void) {
|
|
int ch = read_char_normalized();
|
|
return ch == EOF ? 0 : ch;
|
|
}
|
|
|
|
float getfloat(void) { return read_float_token(); }
|
|
|
|
int getarray(int a[]) {
|
|
int n = getint();
|
|
for (int i = 0; i < n; ++i) {
|
|
a[i] = getint();
|
|
}
|
|
return n;
|
|
}
|
|
|
|
int getfarray(float a[]) {
|
|
int n = getint();
|
|
for (int i = 0; i < n; ++i) {
|
|
a[i] = getfloat();
|
|
}
|
|
return n;
|
|
}
|
|
|
|
void putint(int x) { printf("%d", x); }
|
|
|
|
void putch(int x) { putchar(x); }
|
|
|
|
void putfloat(float x) { printf("%a", (double)x); }
|
|
|
|
void putarray(int n, const int a[]) {
|
|
printf("%d:", n);
|
|
for (int i = 0; i < n; ++i) {
|
|
printf(" %d", a[i]);
|
|
}
|
|
putchar('\n');
|
|
}
|
|
|
|
void putfarray(int n, const float a[]) {
|
|
printf("%d:", n);
|
|
for (int i = 0; i < n; ++i) {
|
|
printf(" %a", (double)a[i]);
|
|
}
|
|
putchar('\n');
|
|
}
|
|
|
|
void starttime(void) {}
|
|
|
|
void stoptime(void) {} |