太难了!
原题链接:30821.操作大师2026-01-25 15:54:13
发布于:天津
谁能告诉我哪错了?
#include<bits/stdc++.h>
using namespace std;
int main(){
int n;
cin>>n;
int si=0,st=si;
string s[10001];
char z;
char p=' ';
for(int i=1;i<=n;i++){
cin>>z;
if(z=='v'){
st++;
si=st;
cin>>s[st];
cout<<s[st]<<endl;
p='v';
}
else if(z=='b'){
if(st<=1){
cout<<"?"<<endl;
}
else{
st--;
cout<<s[st]<<endl;
}
p='b';
}
else if(z=='f'){
if(p=='b'&&st<si){
st++;
cout<<s[st]<<endl;
}
else{
cout<<"?"<<endl;
}
p='f';
}
}
return 0;
}
另一个:
#include<bits/stdc++.h>
using namespace std;
int main(){
int n;
cin>>n;
int si=0,st=si;
string s[n+1];char z,zt=' ';
for(int i=1;i<=n;i++){
cin>>z;
if(z=='v'){si++;st=si;cin>>s[si];cout<<s[si];}
if(z=='b'){
if(st<=1)cout<<'?';
else cout<<s[--st];
}else if(z=='f'){
if(zt=='b'||st==si||zt=='v')cout<<'?';
else cout<<s[++st];
}
cout<<endl;
}
return 0;
}
全部评论 4
#include<bits/stdc++.h> using namespace std; int main(){ int n; cin>>n; int si=0,st=si; string s[10001]; char z; char p=' '; for(int i=1;i<=n;i++){ cin>>z; if(z=='v'){ st++; si=st; cin>>s[st]; cout<<s[st]<<endl; p='v'; } else if(z=='b'){ if(st<=1){ cout<<"?"<<endl; } else{ st--; cout<<s[st]<<endl; } p='b'; } else if(z=='f'){ if(p=='b'&&st<si){ st++; cout<<s[st]<<endl; p='f'; } else{ cout<<"?"<<endl; p='f'; } } } return 0; }我这么写只能过一点
昨天 来自 浙江
0过了有罐头
2天前 来自 浙江
00通过的
2天前 来自 浙江
0这是一个大模拟,仔细看看每个步骤有没有写错的
4天前 来自 浙江
0






























有帮助,赞一个