QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#400138#6750. CalculateericmegalovaniaWA 1ms3788kbC++201.4kb2024-04-27 00:43:002024-04-27 00:43:01

Judging History

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

  • [2024-04-27 00:43:01]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3788kb
  • [2024-04-27 00:43:00]
  • 提交

answer

#include<bits/stdc++.h>//傻逼高精度,大模拟,之后再写
using namespace std;

//#define ONLINE
#ifndef ONLINE
#define debug(...) fprintf(stderr,##__VA_ARGS__)
#else
#define debug(...) ;
#endif

using LL=long long;
using PII=pair<int,int>;

template<typename T>
inline T READ(){
	T x=0; bool f=0; char c=getchar();
	while(c<'0' || c>'9') f|=(c=='-'),c=getchar();
	while(c>='0' && c<='9') x=x*10+c-'0',c=getchar();
	return f?-x:x;
}
inline int read(){return READ<int>();}
inline LL readLL(){return READ<LL>();}
mt19937 rng(chrono::system_clock::now().time_since_epoch().count());

int ans=0,x=0;
int main(){
	ios::sync_with_stdio(false);
	string s; cin>>s;
	vector<int>op{0};
	bool flag=0;
	for(char c:s){
		if(c>='0' && c<='9'){
			x=x*10+c-'0';
		}
		else if(c=='?'){
			x=x*10+(flag?0:9);
		}
		else{
			if(x){
				ans+=flag?-x:x;
				x=0;
			}
			if(c=='('){
				op.push_back(0);
			}
			else if(c==')'){
				op.pop_back();
			}
			else if(c=='+'){
				if(op.back()){
					op.back()=0;
					flag^=1;
				}
			}
			else if(c=='-'){
				if(!op.back()){
					op.back()=1;
					flag^=1;
				}
			}
		}
	}
	if(x){
		ans+=flag?-x:x;
		x=0;
	}
	cout<<ans;
	return 0;
}

/* stuff you should look for
* int overflow, array bounds
* special cases (n=1?)
* do smth instead of nothing and stay organized
* WRITE STUFF DOWN
* DON'T GET STUCK ON ONE APPROACH
*/

詳細信息

Test #1:

score: 100
Accepted
time: 1ms
memory: 3552kb

input:

?+?

output:

18

result:

ok 1 number(s): "18"

Test #2:

score: 0
Accepted
time: 0ms
memory: 3788kb

input:

(?+9)-(?+1)

output:

17

result:

ok 1 number(s): "17"

Test #3:

score: -100
Wrong Answer
time: 0ms
memory: 3576kb

input:

((9)-(((8)-(2))+(((1+(1))-(1+((2)+2+2)))+(5)+4))+(((7)-((9)+3))-((8)-(0-(2))+0))+((6)-(6+(((4)-(9))-(8-((9)+(1))+(0)))+(2-((9)+7))-(1)))-((((7)+(1))-((3)+(3)))-((2)-((6)-((3)-(8)))))+(2+0-((6)-(1))))-((((3)-(((0)+((4)-(9))+((6+8)+4)+(5)-(4-(3)-(8)))-((8)-(2))))+(((2)-(4))+(6)-(2))+(6-(1))-((2+9)-(3+...

output:

105

result:

wrong answer 1st numbers differ - expected: '-63', found: '105'