解题思路:使用STL模板类stack处理元素入栈出栈
注意事项:
参考代码:
#include<iostream> #include<string> #include<stack> #include<list> using namespace std; int main() { int n, i, j; string o1, o2; while (cin >> n >> o1 >> o2) { stack<char> s; list<string> l; i = j = 0; while (i < n) { s.push(o1[i++]); l.push_back("in"); while (j < n) { if (s.empty() || s.top() != o2[j]) break; s.pop(); l.push_back("out"); j++; } } if (s.empty()) { cout << "Yes.\n"; for (auto it = l.begin(); it != l.end(); ++it) cout << *it << '\n'; } else cout << "No.\n"; cout << "FINISH\n"; } return 0; }
0.0分
0 人评分
C语言程序设计教程(第三版)课后习题8.3 (C语言代码)浏览:721 |
A+B for Input-Output Practice (II) (C语言代码)浏览:1006 |
C语言程序设计教程(第三版)课后习题5.7 (C语言代码)浏览:578 |
C语言程序设计教程(第三版)课后习题8.4 (C语言代码)浏览:622 |
IP判断 (C语言代码)浏览:785 |
C语言程序设计教程(第三版)课后习题8.6 (C语言代码)浏览:573 |
完数 (C语言代码)浏览:712 |
Cylinder (C语言描述+详细分析)浏览:3288 |
1118(求助_已解决)浏览:333 |
C二级辅导-同因查找 (C语言代码)浏览:573 |