社区讨论
有点意思:如果不用大多数运算符,你还能写出A+B problem吗?
题目总版参与者 6已保存回复 29
讨论操作
快速查看讨论及其快照的属性,并进行相关操作。
- 当前回复
- 29 条
- 当前快照
- 1 份
- 快照标识符
- @m3soj7k5
- 此快照首次捕获于
- 2024/11/22 19:50 去年
- 此快照最后确认于
- 2025/11/05 01:30 4 个月前
如果禁用大多数运算符,你还能写出A+B problem吗?
那么看看下面这道题吧
A+B 也可以不用一些运算符嘛: (SPJ)。
洛谷 (不支持此题SPJ,仅限看题,请到hydro提交)
以下是该题目中不允许使用的字符和字符串的清单:
- 字符 '+'(加号)
- 字符 '-'(减号)
- 字符 '*'(乘号)
- 字符 '/'(除号)
- 字符 '%'(取模)
- 字符 '^'(异或)
- 字符 '&'(与)
- 字符 '|'(或)
- 字符 '~'(取反)
- 字符 '!'(非)
- 字符串 '>>'(右移运算符)
- 字符串 '<<'(左移运算符)
- 字符串 'and'(逻辑与)
- 字符串 'and_eq'(与赋值)
- 字符串 'bitand'(位与)
- 字符串 'bitor'(位或)
- 字符串 'compl'(按位取反)
- 字符串 'not'(逻辑非)
- 字符串 'not_eq'(不等于)
- 字符串 'or'(逻辑或)
- 字符串 'or_eq'(或赋值)
- 字符串 'xor'(逻辑异或)
- 字符串 'xor_eq'(异或赋值)
题目SPJ
CPP#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;
}
回复
共 29 条回复,欢迎继续交流。
正在加载回复...