10分,求助(样例过了)
查看原帖
10分,求助(样例过了)
558377
jixx楼主2023/6/24 20:17
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
using namespace std;
string s;
long long a[110010],b[110010],ans;
int main(){
	long long k=0,hehe=0,cnt=0;
	cin>>s;
	for(long long i=0;i<s.length();i++){
		if(s[i]=='*'||s[i]=='+'){
			a[++k]=hehe;
			hehe=0;//1+2+4+30+7
		}if(s[i]=='*') b[++cnt]=k;
		else if(s[i]>='0'&&s[i]<='9'){
			hehe*=10;
			hehe+=(s[i]-'0');
		}
	}
	a[++k]=hehe;
	for(long long i=1;i<=cnt;i++){
		if(a[b[i]]!=-1&&a[b[i]+1]!=-1) a[b[i]]=a[b[i]]*a[b[i]+1];
		a[b[i]+1]=-1;
	}
	for(long long i=1;i<=k;i++) if(a[i]!=-1) ans+=a[i];
	cout<<ans%10000<<endl;
	return 0;
}
2023/6/24 20:17
加载中...