洛谷IDE是linux系统评测吗
  • 板块灌水区
  • 楼主sundyLIUXY
  • 当前回复1
  • 已保存回复3
  • 发布时间2024/9/8 11:43
  • 上次更新2024/9/8 15:09:11
查看原帖
洛谷IDE是linux系统评测吗
706737
sundyLIUXY楼主2024/9/8 11:43

rt,同一份代码,交上去就全RE了,运行配置完全相同,数据下载下来在IDE上跑就完全没问题

评测链接

P1054

#include<bits/stdc++.h>
#define int long long
using namespace std;

const int mod = 1000000007;
int m, n, idx, mb;
string s, t[60];

int pr(char ch) {
	if(ch == '+' || ch == '-') return 1;
	if(ch == '*' || ch == '/') return 2;
	if(ch == '^') return 3;
	return 0;
}
void change(string s) {
	stack<char> op;
	int zkh = 0;
	for(int i = 1; i <= n;) {
		if(s[i] == ' ') i++;
		else if(s[i] == '(') zkh++, op.push(s[i]), i++;
		else if(s[i] <= '9' && s[i] >= '0') {
			string num = "";
			while(s[i] <= '9' && s[i] >= '0')
				num += s[i], i++;
			t[++idx] = num;
		}
		else if(s[i] == 'a') t[++idx] = "114514", i++;
		else if(s[i] == ')') {
			if(!zkh) {
				i++;
				continue;
			}
			while(op.size() && op.top() != '(')
				t[++idx] = op.top(), op.pop();
			zkh--, op.pop(), i++;
		}
		else {
			while(op.size() && pr(s[i]) <= pr(op.top()))
				t[++idx] = op.top(), op.pop();
			op.push(s[i]), i++;
		}
	}
	while(op.size()) t[++idx] = op.top(), op.pop();
}
int pw(int a, int b) {
	for(int i = 1; i < b; i++) a = a*a%mod;
	return a%mod;
}
int res(int a, int b, string op) {
	if(op == "+") return (a+b)%mod;
	if(op == "-") return (a-b)%mod;
	if(op == "*") return a*b%mod;
	return pw(a, b)%mod;
}
int slove() {
	stack<int> num;
	for(int i = 1; i <= idx; i++) {
		if(t[i][0] <= '9' && t[i][0] >= '1') {
			int nm = 0;
			for(int j = 0; j < (int)t[i].size(); j++)
				nm = (nm*10+(t[i][j]-'0'))%mod;
			num.push(nm);
		}
		else {
			int b = num.top(); num.pop();
			int a = num.top(); num.pop();
			num.push(res(a, b, t[i]));
			//cout << a << ' ' << b << ' ' << res(a, b, t[i]) << endl;
		}
	}
	return num.top();
}

signed main() {
	getline(cin, s), n = s.size(), s = ' '+s;
	change(s);
	//for(int i = 1; i <= idx; i++) cout << t[i] << ' ';
	mb = slove()/*, cout << mb << endl*/;
	scanf("%lld", &m)/*, cout << m << endl*/;
	getchar();
	for(int i = 1; i <= m; i++) {
		//cout << "ok" << endl;
		s = "", getline(cin, s), n = s.size(), s = ' '+s;
		//cout << s << endl;
		for(int j = 1; j <= 50; j++) t[j] = "";
		idx = 0, change(s);
		int dq = slove();
		if(dq == mb) cout << char('A'+i-1);
	}

    return 0;
}
2024/9/8 11:43
加载中...