hdu 1022 Train Problem I (栈的应用)
2014-05-05 18:02
459 查看
[align=left]Sample Input[/align]
[align=left]Sample Output[/align]
[/code]
3 123 321 3 123 312
[align=left]Sample Output[/align]
Yes. in in in out out out FINISH No. FINISH 考察栈的应用,给定序列str1和str2,问你能否在str1的基础上只进行入栈 出栈得到str2 用stl水就可以了 但是我水的很艰难啊 各种WA 直接上代码吧: [code]#include <cstdio> #include <vector> #include <stack> #include <string> #include <iostream> #include <algorithm> #define MAXN 10010 #define ll long long using namespace std; vector<string> ans; int main(void) { int n; string str1, str2; stack<char> st; while(scanf("%d", &n) != EOF) { ans.clear(); while(!st.empty())//用栈的时候千万记得清空栈 st.pop(); cin >> str1 >> str2; int len = str1.size(); int i = 0; int j = 0; while(i<len) { st.push(str1[i++]); ans.push_back("in"); while(!st.empty() && st.top() == str2[j]) {//每次要一直退栈到不能退为止 st.pop(); ans.push_back("out"); ++j; } } while(j < len) { if(st.top() == str2[j]) { st.pop(); ans.push_back("out"); } ++j; } if(st.empty()) { cout << "Yes." << endl; for(int i=0; i<ans.size(); ++i) { cout << ans[i] << endl; } } else cout << "No." << endl; cout << "FINISH" << endl; } return 0; }
[/code]
相关文章推荐
- HDU1022--Train Problem I(栈的应用)
- hdu-1022 Train Problem I (栈的简单应用)
- hdu 1022 Train Problem I(栈的应用。。。)
- hdu 1022 Train Problem I(栈的应用+STL)
- HDU 1022:Train Problem I(堆栈的基本应用)
- hdu 1022 Train Problem I (栈的简单应用)
- hdu 1022 Train Problem I_栈的应用经典例题
- HDU 1022 Train Problem I(栈的简单应用)
- hdu 1022 Train Problem I(栈的应用+STL)
- HDU-1022 Train Problem I (栈的简单应用)
- Hdu 1022 Train Problem I (栈的简单应用)
- hdu1022 Train Problem I(STL 栈的应用)
- hdu 1022 Train Problem I (栈的应用)
- hdu 1022 Train Problem I(栈的应用)
- HDU1022 Train Problem I
- HDU 1022 Train Problem I
- Train Problem I hdu 1022 栈
- hdu 1022 Train Problem I(stack)
- HDU 1022 Train Problem I
- HDU 1022 Train Problem I