一些工具

批量造数据板子

点击查看代码
#include<bits/stdc++.h>

using namespace std;

char command[100000];

string cvs1(int num){
  string res = "";
  do
    res += num % 10 + '0', num /= 10;
  while(num > 0);
  reverse(res.begin(), res.end());
  return res;
}

char* cvs2(string s){
  memset(command, 0, sizeof(command));
  for(int i = 0; i < s.size(); ++i)
    command[i] = s[i];
  return command;
}

int cvs3(char *s){
  int num = 0, len = strlen(s);
  for(int i = 0; i < len; ++i)
    num = num * 10 + s[i] - '0';
  return num;
}

int main(int num, char *arvg[]){
  int L = cvs3(arvg[1]), R = cvs3(arvg[2]);
  system("g++ -o make_data make_data.cpp");
  system("g++ -o std std.cpp");
  system("mkdir data");
  for(int i = L; i <= R; ++i){
    system(cvs2((string)"./make_data > " + (string)"./data/data_" + cvs1(i) + (string)".in"));
    system(cvs2((string)"./std < " + (string)"./data/data_" + cvs1(i) + (string)".in > " + (string)"./data/data_" + cvs1(i) + (string)".out"));
  }
  return 0;
}

对拍板子

点击查看代码
#include<bits/stdc++.h>
#include<unistd.h>

using namespace std;

void sleep(int time){
  usleep(1000ll * time);
  return;
}

void waiting(){
  for(int i = 0; i <= 100; ++i){
    system("clear");
    printf("正在确认操作 %3d%%", i);
    fflush(stdout);
    sleep(rand() % 4 + 1);
  }
  sleep(950 + rand() % 101);
  system("clear");
  printf("操作确认完毕!正在编译代码......\n");
  sleep(500);
  return;
}

int main(){
  srand(time(0) * clock());
  waiting();

  int CE = 0;
  CE |= (system("g++ -o data data.cpp -fsanitize=undefined") != 0) * 1;
  CE |= (system("g++ -o code code.cpp -fsanitize=undefined") != 0) * 2;
  CE |= (system("g++ -o std std.cpp -fsanitize=undefined") != 0) * 4;
  if(CE){
    printf("#Compile Error : data(%d) code(%d) std(%d)\n", (CE & 1) > 0, (CE & 2) > 0, (CE & 4) > 0);
    return 0;
  }
  system("clear");
  
  int n = 0;
  while(++n){
    int RE = 0;
    RE |= (system("./data > data.in") != 0) * 1;
    RE |= (system("./std < data.in > data.ans") != 0) * 2;
    RE |= (system("./code < data.in > data.out") != 0) * 4;
    if(RE){
      printf("#Runtime Error : data(%d) code(%d) std(%d)\n", (RE & 1) > 0, (RE & 2) > 0, (RE & 4) > 0);
      return 0;
    }
    if(system("diff data.out data.ans")){
      system("clear");
      printf("Wrong Answer on test #%d\n",n);
      break;
    }
    system("clear");
    printf("Accept on test #%d\n",n);
  }
  return 0;
}

一键编译运行板子

点击查看代码
#include<bits/stdc++.h>
#define ll long long

using namespace std;

char APPLE[1000005];

string cvs(char *s){
  int ls = strlen(s);
  string res = "";
  for(int i = 0; i < ls; ++i)
    res += s[i];
  return res;
}

char* svc(string s){
  for(int i = 0; i < s.size(); ++i)
    APPLE[i] = s[i];
  APPLE[s.size()] = 0;
  return APPLE;
}

ll cvn(char *s){
  int ls = strlen(s), fh = (s[0] == '-' ? -1 : 1);
  ll res = 0;
  for(int i = (s[0] == '-'); i < ls; ++i)
    res = res * 10 + s[i] - '0';
  return res * fh;
}

int main(int num, char **name){
  string cpp = cvs(name[1]);
  int step = (num > 2 ? cvn(name[2]) : 2);
  string other = cvs(".cpp") + (num > 3 ? cvs(" ") + cvs(name[3]) : "");
  if(step > 0)
    system(svc(cvs("g++ -o ") + cpp + cvs(" ") + cpp + other));
  if(step > 1)
    system(svc(cpp));
  return 0;
}
posted @ 2023-11-06 15:25  静观默察  阅读(22)  评论(0)    收藏  举报