weekly_problem_snippet/snippet.c

90 lines
2.4 KiB
C
Raw Permalink Normal View History

2024-11-27 23:41:38 +08:00
// Created by Synth Magic
// 2024-11-27 22:57
// TODO: Refactor the code by need
// TODO: Add ExceptionHandler on windows and signal system on linux
#include <ctype.h>
#include <minwindef.h>
#include <stdarg.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <vadefs.h>
2024-11-28 23:28:30 +08:00
#define MAX_IONUM 100000
2024-11-27 23:41:38 +08:00
// Time Limit (normally 1s)
// 题目的时限(通常为1秒)
const unsigned int case_millseconds = 1000;
unsigned int curr_testcase = 0, sum_mark = 0;
size_t cur_output = 0;
#if defined(_WIN32) || defined(__CYGWIN__) || defined(_WIN64)
#include <windows.h>
2024-11-28 23:28:30 +08:00
HANDLE child_stdout_r = NULL;
void create_process() {
PROCESS_INFORMATION piProcInfo;
STARTUPINFO siStartInfo;
BOOL bSuccess = FALSE;
ZeroMemory(&piProcInfo, sizeof(PROCESS_INFORMATION));
ZeroMemory(&siStartInfo, sizeof(STARTUPINFO));
2024-11-27 23:41:38 +08:00
}
#elif defined(__linux__)
2024-11-28 23:28:30 +08:00
#warning not finished
2024-11-27 23:41:38 +08:00
#endif
#if defined(__APPLE__) || defined(__MACH__) || defined(BSD)
#error Unsupported OS
#endif
char *trim(char *s) {
while (isspace(*s))
s++;
char *back = s + strlen(s);
while (isspace(*--back))
;
*(back + 1) = '\0';
return s;
}
unsigned int crc32f(unsigned char *message) {
int i = 0, j;
unsigned int byte, crc = 0xFFFFFFFF, mask;
while (message[i] != 0) {
byte = message[i];
crc = crc ^ byte;
for (j = 7; j >= 0; j--) {
mask = -(crc & 1);
crc = (crc >> 1) ^ (0xEDB88320 & mask);
}
i = i + 1;
}
return ~crc;
}
2024-11-28 23:28:30 +08:00
int a_plus_b(int a, int b) { return a + b; }
/**
TESTCASE(1) {
2024-11-27 23:41:38 +08:00
2024-11-28 23:28:30 +08:00
}
subprocess:
if result present in time limit * 2 : print crc and time
if not present & still running : TLE
if exit != 0 : RE
*/
#define BEGIN_TESTCASE switch (atoi(argv[2])) {
#define TESTCASE(i, x) \
case i: { \
x; \
break; \
2024-11-27 23:41:38 +08:00
}
2024-11-28 23:28:30 +08:00
#define END_TESTCASE \
default: \
break; \
}
void test() {}
int main(int argc, const char *argv[]) {
if (argc == 3) {
BEGIN_TESTCASE
TESTCASE(1, printf("1"))
END_TESTCASE
2024-11-27 23:41:38 +08:00
} else {
}
}