chenhaoyang2008 @ 2024-11-22 19:49:26
HydroOJ
洛谷 (不支持此题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;
}
by litjohn @ 2024-11-22 19:53:28
@chenhaoyang2008 你这样读入都很困难吧。
by litjohn @ 2024-11-22 19:54:07
@chenhaoyang2008我好像知道了:用文言。
by Grammar__hbw @ 2024-11-22 19:54:23
@chenhaoyang2008 &和<<至少留一个才能输入
by Grammar__hbw @ 2024-11-22 19:54:36
@litjohn 正确的
by qazsedcrfvgyhnujijn @ 2024-11-22 19:55:33
没法 IO 啊
by XuYueming @ 2024-11-22 19:55:56
@chenhaoyang2008 首先你这个 checker 就不对:
#include <cstdio>
#include <tuple>
#define AND b##itand
#define XOR x##or
#define LSHIFT <##<
int a, b;
int add(int a, int b) {
int x = a AND b, y = a XOR b;
while (x) {
std::tie(x, y) = std::make_tuple(y AND x LSHIFT 1, y XOR x LSHIFT 1);
}
return y;
}
signed main() {
scanf("%d%d", &a, &b);
printf("%d", add(a, b));
return 0;
}
by XuYueming @ 2024-11-22 19:56:36
@XuYueming 哦哦哦,忘记处理位与了
by XuYueming @ 2024-11-22 19:57:29
@chenhaoyang2008 这样:
#include <cstdio>
#include <tuple>
#define AND b##itand
#define XOR x##or
#define LSHIFT <##<
int a, b;
int add(int a, int b) {
int x = a AND b, y = a XOR b;
while (x) {
std::tie(x, y) = std::make_tuple(y AND x LSHIFT 1, y XOR x LSHIFT 1);
}
return y;
}
signed main() {
scanf("%d%d", AND a, AND b);
printf("%d", add(a, b));
return 0;
}
by XuYueming @ 2024-11-22 20:01:01
@chenhaoyang2008 不是哥们,字符串里的 %
也管?那得处理一下了。
by chenhaoyang2008 @ 2024-11-22 20:01:19
@Grammar__hbw getchar putchar