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.
99 lines
1.7 KiB
99 lines
1.7 KiB
// SysY 运行库实现:
|
|
// - 按实验/评测规范提供 I/O 等函数实现
|
|
// - 与编译器生成的目标代码链接,支撑运行时行为
|
|
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
#include <time.h>
|
|
|
|
// 输入函数
|
|
int getint() {
|
|
int value;
|
|
scanf("%d", &value);
|
|
return value;
|
|
}
|
|
|
|
int getch() {
|
|
char ch;
|
|
scanf("%c", &ch);
|
|
return (int)ch;
|
|
}
|
|
|
|
float getfloat() {
|
|
float value;
|
|
scanf("%f", &value);
|
|
return value;
|
|
}
|
|
|
|
int getarray(int arr[]) {
|
|
int n;
|
|
scanf("%d", &n);
|
|
for (int i = 0; i < n; i++) {
|
|
scanf("%d", &arr[i]);
|
|
}
|
|
return n;
|
|
}
|
|
|
|
int getfarray(float arr[]) {
|
|
int n;
|
|
scanf("%d", &n);
|
|
for (int i = 0; i < n; i++) {
|
|
scanf("%f", &arr[i]);
|
|
}
|
|
return n;
|
|
}
|
|
|
|
// 输出函数
|
|
void putint(int value) {
|
|
printf("%d", value);
|
|
}
|
|
|
|
void putch(int ch) {
|
|
printf("%c", (char)ch);
|
|
}
|
|
|
|
void putfloat(float value) {
|
|
printf("%a", value);
|
|
}
|
|
|
|
void putarray(int n, int arr[]) {
|
|
printf("%d:", n);
|
|
for (int i = 0; i < n; i++) {
|
|
printf(" %d", arr[i]);
|
|
}
|
|
printf("\n");
|
|
}
|
|
|
|
void putfarray(int n, float arr[]) {
|
|
printf("%d:", n);
|
|
for (int i = 0; i < n; i++) {
|
|
printf(" %a", arr[i]);
|
|
}
|
|
printf("\n");
|
|
}
|
|
|
|
// putstr 在测试用例中定义
|
|
|
|
// 计时函数
|
|
static clock_t start_time = 0;
|
|
|
|
void starttime() {
|
|
start_time = clock();
|
|
}
|
|
|
|
void stoptime() {
|
|
clock_t end_time = clock();
|
|
double elapsed = (double)(end_time - start_time) / CLOCKS_PER_SEC;
|
|
fprintf(stderr, "Total time: %.6f seconds\n", elapsed);
|
|
}
|
|
|
|
// 内存管理函数(如果需要)
|
|
void* _sysy_allocate(int size) {
|
|
return malloc(size);
|
|
}
|
|
|
|
void _sysy_deallocate(void* ptr) {
|
|
free(ptr);
|
|
}
|