QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#371576#6750. CalculateKryc#WA 1ms3812kbC++172.1kb2024-03-30 14:06:522024-03-30 14:06:54

Judging History

你现在查看的是最新测评结果

  • [2024-03-30 14:06:54]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3812kb
  • [2024-03-30 14:06:52]
  • 提交

answer

#include<iostream>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<queue>
#include<stack>
#include<vector>
#include<deque>
#include<map>
#define x first
#define y second
#define ll long long
#define ULL unsigned long long
using namespace std;

typedef pair<int, int> PII;

const int N = 2e5 + 10;
const int mod = 1e9 + 7;
const int inf = 0x3f3f3f3f;

stack<int> num;
stack<char> op;

void eval()
{
	int a = num.top();
	num.pop();
	int b = num.top();
	num.pop();
	char c = op.top();
	op.pop();
	int x;
	if(c == '-') x = b - a;
	else if( c == '+') x = a + b;
	num.push(x);
}

void solve()
{
	string s;
	cin >> s;
	int len = s.length();
	int ans = 0, f1 = 0, f2 = 0;
	for(int i = 0; i < len; i ++ )
	{
		if(isdigit(s[i])) 
		{
			if(f2)
			{
				if(op.top() == '-')
					num.push(-(int)(s[i] - '0'));
				else 
					num.push((int)(s[i] - '0'));
				op.pop();
				f2 = 0;
			}
			else
				num.push((int)(s[i] - '0'));
		}
		
		else if(s[i] == '?')
		{
			f2 = 1;
			if(f1)
			{
				if(op.top() == '-')
				{
					ans ++;
					op.pop();					
				}	
				else if(op.top() == '+') op.pop();
			}
			else
			{
				if(i == 0) ans ++;
				else if(op.size())
				{
					if(op.top() == '(') ans ++;
					else if(op.top() == '+') ans ++, op.pop();
					else if(op.top() == '-') op.pop();				
				}					
			}
			
		} 
		
		else if(s[i] == '(') 
		{
			if(op.size() && op.top() == '-') f1 = 1;
			op.push(s[i]);
		}
		else if(s[i] == ')')
		{
			while(op.top() != '(' && op.size()) eval();
			op.pop();	
			num.push(0);
			f1 = 0;
		}
		
        else 
        {
            while(op.size() && op.top() != '(') eval();//&& num.size() > 1 
            op.push(s[i]);
        }
        
	}

	num.push(0);
	while(op.size()) eval();
	
	if(num.size()) cout << num.top() << ' ';
	else cout << 0 << ' ';
    cout << ans << endl; 
   /*
    int sum = 0;
    if(num.size()) sum += num.top();
    cout << sum + ans * 9 << endl; */
}

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int t;
	//cin >> t;
	t = 1;
	while(t -- )
		solve();
	return 0;
}


详细

Test #1:

score: 0
Wrong Answer
time: 1ms
memory: 3812kb

input:

?+?

output:

0 2

result:

wrong answer 1st numbers differ - expected: '18', found: '0'