题目有问题吗?
查看原帖
题目有问题吗?
1355142
Mo_Ying楼主2024/8/21 13:10

我刚才用我自己的代码放到这道题中测试,样例全部通过,测试全部出错(运行出错)但是我在“东方博宜oj”测试(相同题目),全部通过。 东方博宜oj题目网站:https://oj.czos.cn/contest/problem?id=16004&pid=2&_pjax=%23p0

我的代码如下:

#include<bits/stdc++.h>
using namespace std;
int main(){
	string s;
	short ja =  0;
	bool n;
	cin >> s;
	s += '+';
//	getline(cin, s);
	stack<unsigned short> z;
//	cout << s;
	for(int i = 0; i < s.size(); i++){
		if(s[i] >= '0' && s[i] <= '9')z.push(0);
		while(s[i] >= '0' && s[i] <= '9'){
			unsigned short x = z.top();
			z.pop();
			x = (x * 10 + (unsigned short)(s[i] - '0')) % 10000;
//			cout << " x:" << x << " ";
			z.push(x);
			i++;
		}
		if(n){
			unsigned short x = z.top();
			z.pop();
			unsigned short y = z.top();
			z.pop();
//			cout << " y:" << (x * y) % 10000 << " ";
			z.push((x * y) % 10000);
			n = 0;
		}
		if(s[i] == '+'){
			ja++;
			if(ja == 2){
				unsigned short x = z.top();
				z.pop();
				unsigned short y = z.top();
				z.pop();
//				cout << "y:" << (x * y) % 10000 << " ";
				z.push((x + y) % 10000);
				ja--;
			}
		}else{
			n = 1;
		}
	}
//	cout << endl;
	cout << z.top();
}

有没有人解惑一下

2024/8/21 13:10
加载中...