QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#90040 | #5490. Smallest Calculated Value | ChatGPT | WA | 2ms | 3360kb | C++23 | 1.5kb | 2023-03-22 02:54:13 | 2023-03-22 02:54:14 |
Judging History
answer
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main() {
// read in the three integers
int a, b, c;
cin >> a >> b >> c;
// generate all possible orderings of the operators
vector<char> operators {'+', '-', '*', '/'};
vector<vector<char>> orders;
for (char op1 : operators) {
for (char op2 : operators) {
for (char op3 : operators) {
orders.push_back({op1, op2, op3});
}
}
}
// iterate through all possible orderings of the operators
int min_result = 1000;
for (auto order : orders) {
// apply the operators to the three integers
int result = a;
for (char op : order) {
if (op == '+') {
result += b;
} else if (op == '-') {
result -= b;
} else if (op == '*') {
result *= b;
} else if (op == '/') {
if (result % b == 0) {
result /= b;
} else {
// skip this order if integer division is not possible
break;
}
}
b = c;
}
// update the minimum non-negative result
if (result >= 0 && result < min_result) {
min_result = result;
}
}
// output the minimum non-negative result
cout << min_result << endl;
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 3340kb
input:
2 3 5
output:
0
result:
ok single line: '0'
Test #2:
score: 0
Accepted
time: 2ms
memory: 3316kb
input:
9 9 9
output:
0
result:
ok single line: '0'
Test #3:
score: -100
Wrong Answer
time: 1ms
memory: 3360kb
input:
5 7 3
output:
2
result:
wrong answer 1st lines differ - expected: '1', found: '2'