洛谷 (不支持此题SPJ,仅限看题,请到hydro提交)
以下是该题目中不允许使用的字符和字符串的清单:
#include "testlib.h"
#include <bits/stdc++.h>
using namespace std;
int main(int argc, char* argv[]) {
setName("A+B no '+' checker");
registerTestlibCmd(argc, argv);
ifstream cod("user_code");
if (!cod.is_open()) {
quitf(_fail, "Could not open user code file");
}
string line, userCode;
while (getline(cod, line)) {
userCode += line;
}
vector<string> forbidden = {
"+", "-", "*", "/", "%", "^", "&", "|", "~", "!", ">>", "<<",
"and", "and_eq", "bitand", "bitor", "compl", "not",
"not_eq", "or", "or_eq", "xor", "xor_eq"
};
for (const auto& item : forbidden) {
if (userCode.find(item) != string::npos) {
quitf(_wa, "User code contains the '%s' character.", item.c_str());
}
}
int a = inf.readInt();
int b = inf.readInt();
int userSum = ouf.readInt();
if (userSum != a + b) {
quitf(_wa, "Wrong sum. Expected %d, but found %d.", a + b, userSum);
}
quitf(_ok, "Accepted! Correct sum without using these character.");
return 0;
}