社区讨论
本地测试AC,洛谷RE
灌水区参与者 3已保存回复 7
讨论操作
快速查看讨论及其快照的属性,并进行相关操作。
- 当前回复
- 7 条
- 当前快照
- 1 份
- 快照标识符
- @lzowdv9f
- 此快照首次捕获于
- 2024/08/11 09:40 2 年前
- 此快照最后确认于
- 2024/08/11 11:04 2 年前
本地测试AC,交上去全RE
CPP#include<iostream>
#include<cstring>
#include<algorithm>
#include<stack>
#include<unordered_map>
#include<cmath>
#define int long long
using namespace std;
stack<int> num;
stack<char> op;
const int N = 30;
string data[N];
string str , d , ans;
int n;
int test[] = {0 , 0 , 1 , 2 , 17 , 19 , 23};
unordered_map<char , int> pri{{'+' , 1} , {'-' , 1} , {'*' , 2} , {'/' , 2} , {'^' , 3}};
string remove(string str){
string ans;
for(int i = 0;i < str.size();i++) if(str[i] != ' ') ans += str[i];
return ans;
}
void eval(){
int y = num.top(); num.pop();
int x = num.top(); num.pop();
char z = op.top(); op.pop();
if(z == '+') num.push(x + y);
if(z == '-') num.push(x - y);
if(z == '*') num.push(x * y);
if(z == '^') num.push(pow(x , y));
}
int Eval(string t , int value){
while(op.size()) op.pop();
while(num.size()) num.pop();
for(int i = 0;i < t.size();i++){
char x = t[i];
if(x == 'a') num.push(value);
else if(x >= '0' && x <= '9'){
int j = i;
int g = 0;
while(j < t.size() && t[j] >= '0' && t[j] <= '9') g = g * 10 + t[j++] - '0';
num.push(g);
i = j - 1;
}
else if(x == '(') op.push(x);
else if(x == ')'){
while(op.size() && op.top() != '(') eval();
op.pop();
}
else if(x == '^') op.push(x);
else{
while(op.size() && pri[op.top()] >= pri[x]) eval();
op.push(x);
}
}
while(op.size()) eval();
return num.top();
}
bool check(string data){
for(int i = 1;i <= 6;i++) if(Eval(str , test[i]) != Eval(data , test[i])) return false;
return true;
}
signed main(){
getline(cin , str);
str = remove(str);
cin >> n;
getline(cin , d);
for(int i = 1;i <= n;i++){
getline(cin , data[i]);
data[i] = remove(data[i]);
}
for(int i = 1;i <= n;i++) if(check(data[i])) ans += char('A' + i - 1);
cout << ans << endl;
return 0;
}
回复
共 7 条回复,欢迎继续交流。
正在加载回复...