跳到正文

剪贴板

剪贴板 7iygt58d

原文
剪贴板信息

剪贴板信息

收录
更新

dp.cpp(对拍程序):

C++
#include <bits/stdc++.h>
int main () {
  system ("g++ apb.cpp -o apb -Wall -O2 -std=c++14");
  int testtt = 0;
  while (++testtt) {
    system ("./gen 10 > apb.in");
    // 这个 10 是可变的,变成你想要的数据范围,10 的含义见 gen.cpp
    system ("./apb");
    system ("./sol < apb.in > apb.ans");
    if (system ("diff apb.out apb.ans")) {
      printf ("Wrong answer on test %d;\n", testtt);
      break;
    }
    printf ("Accepted on test %d;\n", testtt);
  }
  system ("diff apb.out apb.ans");
}

apb.cpp(选手程序):

C++
#include <cstdio>
int main () {
  freopen ("apb.in","r",stdin);
  freopen ("apb.out","w",stdout);
  int a, b;
  scanf ("%d%d", &a, &b);
  printf ("%d\n", a + b);
  if (!a) printf ("w\n");
}

sol.cpp(正解 / 暴力程序):

C++
#include <bits/stdc++.h>
int main () {
  int a, b ;
  std :: cin >> a >> b;
  std :: cout << a + b << std :: endl;
  return 0;
}

gen.cpp(数据生成程序)

C++
#include <bits/stdc++.h>
inline int eval (char* arg) {
  int l = strlen (arg), x = 0;
  for(int i = 0; i < l; i++) x = x * 10 + arg[i] - '0';
  return x;
}
signed main (int argc, char** argv) {
  srand (time(0));
  int MOD = eval (argv[1]);
  int a = rand () % MOD, b = rand () % MOD;
  std :: cout << a << " " << b << std :: endl;
}

效果:

代码
noi@noi-Standard-PC-Q35-ICH9-2009:~/Desktop/qwq$ g++ gen.cpp -o gen -Wall -O3
noi@noi-Standard-PC-Q35-ICH9-2009:~/Desktop/qwq$ g++ sol.cpp -o sol -Wall -Wextra -Wshadow -O3 -fsanitize=address
noi@noi-Standard-PC-Q35-ICH9-2009:~/Desktop/qwq$ g++ dp.cpp -o dp

(先编译三个程序,选手程序留给 dp.cpp 编译。然后运行 dp)

代码
noi@noi-Standard-PC-Q35-ICH9-2009:~/Desktop/qwq$ ./dp
apb.cpp: In function ‘int main()’:
apb.cpp:3:11: warning: ignoring return value of ‘FILE* freopen(const char*, const char*, FILE*)’, declared with attribute warn_unused_result [-Wunused-result]
    3 |   freopen ("apb.in","r",stdin);
      |   ~~~~~~~~^~~~~~~~~~~~~~~~~~~~
apb.cpp:4:11: warning: ignoring return value of ‘FILE* freopen(const char*, const char*, FILE*)’, declared with attribute warn_unused_result [-Wunused-result]
    4 |   freopen ("apb.out","w",stdout);
      |   ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
apb.cpp:6:9: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
    6 |   scanf ("%d%d", &a, &b);
      |   ~~~~~~^~~~~~~~~~~~~~~~
Accepted on test 1;
Accepted on test 2;
Accepted on test 3;
Accepted on test 4;
Accepted on test 5;
Accepted on test 6;
Accepted on test 7;
Accepted on test 8;

......

Accepted on test 333;
Accepted on test 334;
Accepted on test 335;
2d1
< w
Wrong answer on test 336;
2d1
< w