解题思路:使用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语言程序设计教程(第三版)课后习题10.4 (C语言代码)浏览:587 |
矩形面积交 (C语言代码)浏览:1526 |
C语言程序设计教程(第三版)课后习题10.5 (C语言代码)浏览:748 |
简单的a+b (C语言代码)浏览:566 |
C语言训练-排序问题<1> (C++代码)浏览:615 |
C语言训练-计算1977!* (C++代码)浏览:874 |
Pascal三角 (C语言代码)格式错误浏览:535 |
C语言程序设计教程(第三版)课后习题5.4 (C语言代码)浏览:531 |
【金明的预算方案】 (C++代码)浏览:855 |
简单的a+b (C语言代码)浏览:603 |