酷代码 AI
菜单
全部AI  /  热门  /  AI写代码神器
服务商

// // main.cpp // step1 // // created by ljpc on 2018/8/31. // copyright © 2018年 ljpc. all rights reserved. // #include <iostream> #include <stack> #include <cstring> #include <algorithm> using namespace std; int main(int argc, const char * argv[]) { // 请在这里补充代码,完成本关任务 /********* begin *********/ stack<char> s1; stack<char> s2; char s[200]; fgets(s,200,stdin); int len=strlen(s); if(s[len-1]=='\n'){ s[len-1]='\0'; len--; } char

*p=s; while(p-s<len){ if(*p=='<'){ if(!s1.empty()){ s2.push(s1.top()); s1.pop(); } } else if(*p=='>'){ if(!s2.empty()){ s1.push(s2.top()); s2.pop(); } } else if(*p=='-'){ if(!s1.empty()){ s1.pop(); } } else { s1.push(*p); } p++; } while(!s1.empty()){ s2.push(s1.top()); s1.pop(); } string ans; while(!s2.empty()){ ans+=s2.top(); s2.pop(); } reverse(ans.begin(), ans.end()); cout<<ans<<endl; /* end */ return 0; } [2024-10-25 17:28:04 | AI写代码神器 | 518点数解答]

相关提问