HDU - 1022 |
---|
题意: 给定一个入栈顺序和一个出栈顺序,判断是否符合出栈的规则。
#include<bits/stdc++.h>
using namespace std;
#define endl "\n"
int n;
string a, b;
void run() {
vector<int> ans;
stack<char> s;
int c1 = 0, c2 = 0;
while(c2 < n) {
if(s.empty() || s.top() != b[c2]) {
if(c1 == a.length()) break;
s.push(a[c1++]);
ans.push_back(1);
}
if(s.top() == b[c2]) {
c2++;
s.pop();
ans.push_back(0);
}
}
if(s.empty()) {
cout << "Yes." << endl;
for(int i = 0; i < ans.size(); i++) {
if(ans[i]) cout << "in" << endl;
else cout << "out" << endl;
}
} else {
cout << "No." << endl;
}
cout << "FINISH" << endl;
}
int main() {
while(cin >> n >> a >> b) run();
return 0;
}