社区讨论
先不说TLE的事,为啥我WA啊
P15233「CROI · R3」浣熊的蒲公英参与者 2已保存回复 2
讨论操作
快速查看讨论及其快照的属性,并进行相关操作。
- 当前回复
- 2 条
- 当前快照
- 1 份
- 快照标识符
- @mlhgikze
- 此快照首次捕获于
- 2026/02/11 11:15 上周
- 此快照最后确认于
- 2026/02/11 13:35 上周
CPP
#include<bits/stdc++.h>
using namespace std;
const int m=1e9+7;
string s;int q,k,a;char c;
int mod(int x){
if(x>=0) return x%m;
else return mod(m+x);
}
int getint(int i){
int cnt=0;
for(int j=i;'0'<=s[j] and s[j]<='9' and j<s.size();j++){
cnt=cnt*10+(s[j]-'0');
}
return mod(cnt);
}
int work(){
int f=1;
int cnt=1,ans=0;
for(int i=0;i<s.size();i++){
if('0'<=s[i] and s[i]<='9'){
cnt*=getint(i);
cnt=mod(cnt);
//cout<<cnt<<endl;
while(s[i]!='*' and s[i]!='+' and s[i]!='-' and i<s.size())
i++;
i--;
continue;
}
if(s[i]=='+'){
ans+=mod(cnt)*f;
//cout<<ans<<endl;
cnt=1;
f=1;
}
if(s[i]=='-'){
ans+=mod(cnt)*f;
//cout<<ans<<endl;
cnt=1;
f=-1;
}
}
ans+=f*(cnt);
return mod(ans);
}
int main(){
cin>>s>>q;
cout<<work()<<'\n';
while(q--){
cin>>k>>c;
int sum=0,i=0;
while(sum<k and i<s.size()){
if(s[i]<'0' or s[i]>'9')
sum++;
i++;
}
if(s[i-1]=='*' and c!='*'){
s[i-1]=c;
//cout<<s+"\n";
cout<<work()<<'\n';
}
}
return 0;
}
俩样例都过了,但WA*2/3+TLE*1/3
回复
共 2 条回复,欢迎继续交流。
正在加载回复...