RT。 在https://www.luogu.com.cn/record/61824603和https://www.luogu.com.cn/record/61824725的对比中,我们可以发现,两者本意相同的代码却一个10分,一个100分。
十分代码:
#include<bits/stdc++.h>
using namespace std;
string s;
char ch[100005];
int sh[100005],t,t1;
int main(){
// freopen("cpp.in","r",stdin);
// freopen("cpp.out","w",stdout);
cin>>s;
for(int i=0;i<s.size();i++){
switch(s[i]){
case '+':{
while(ch[t1]=='*'){
// t--;这里
sh[--t]=sh[t]*sh[t+1];
sh[t]%=10000;
// cout<<'*'<<'2';
t1--;
}
ch[++t1]='+';
// cout << t << " " << sh[t] << endl;
break;
}
case '*':{
ch[++t1]='*';
break;
}
default :{
sh[++t]=0;
while(s[i]>='0'&&s[i]<='9'){
sh[t]=sh[t]*10+s[i]-'0';
sh[t]%=10000;
i++;
}
// cout << t << " " << sh[t] << endl;
i--;
break;
}
}
}
while(t1){
if(ch[t1]=='*'){
// cout << 1 << " " << sh[t - 1] << " " << sh[t] << endl;
// t--;这里
sh[--t]=sh[t]*sh[t+1];
sh[t]=sh[t] % 10000;
// cout<<'*'<<'2';
}
else{
// cout << 2 << " " << sh[t - 1] << " " << sh[t] << endl;
// t--;这里
sh[--t]=sh[t]+sh[t+1];
sh[t]=sh[t] % 10000;
// cout<<'+'<<'2';
}
t1--;
}
// cout<<endl;
cout<<sh[1]%10000;
}
100分:
#include<bits/stdc++.h>
using namespace std;
string s;
char ch[100005];
int sh[100005],t,t1;
int main(){
// freopen("cpp.in","r",stdin);
// freopen("cpp.out","w",stdout);
cin>>s;
for(int i=0;i<s.size();i++){
switch(s[i]){
case '+':{
while(ch[t1]=='*'){
t--;
sh[t]=sh[t]*sh[t+1];
sh[t]%=10000;
// cout<<'*'<<'2';
t1--;
}
ch[++t1]='+';
// cout << t << " " << sh[t] << endl;
break;
}
case '*':{
ch[++t1]='*';
break;
}
default :{
sh[++t]=0;
while(s[i]>='0'&&s[i]<='9'){
sh[t]=sh[t]*10+s[i]-'0';
sh[t]%=10000;
i++;
}
// cout << t << " " << sh[t] << endl;
i--;
break;
}
}
}
while(t1){
if(ch[t1]=='*'){
// cout << 1 << " " << sh[t - 1] << " " << sh[t] << endl;
t--;
sh[t]=sh[t]*sh[t+1];
sh[t]=sh[t] % 10000;
// cout<<'*'<<'2';
}
else{
// cout << 2 << " " << sh[t - 1] << " " << sh[t] << endl;
t--;
sh[t]=sh[t]+sh[t+1];
sh[t]=sh[t] % 10000;
// cout<<'+'<<'2';
}
t1--;
}
// cout<<endl;
cout<<sh[1]%10000;
}