问题陈述:
杭州电子科技大学HANGZHOU DIANZI UNIVERSITY Online Judge Problem - 1022
问题解析:
栈(stack)的简单应用
代码详解:
1 #include <iostream> 2 #include <cstdio> 3 #include <stack> 4 #include <cstring> 5 6 using namespace std; 7 8 stack<int> s; 9 10 int flag[100]; 11 12 int main() 13 { 14 int n, i, j, k; 15 char o1[20], o2[20]; 16 while(~scanf("%d %s%s", &n, o1, o2)){ 17 while(!s.empty()){ 18 s.pop(); 19 } 20 memset(flag, -1, sizeof(flag)); 21 j = k = 0; 22 for(i=0; i<n; i++) { 23 s.push(o1[i]); 24 flag[k++] = 1; 25 while(!s.empty() && s.top()==o2[j]) { 26 s.pop(); 27 flag[k++] = 0; 28 j++; 29 } 30 } 31 if(j == n) { 32 cout << "Yes." <<endl; 33 for(i=0; i<k; i++) { 34 if(flag[i]) { 35 cout << "in" <<endl; 36 }else { 37 cout << "out" << endl; 38 } 39 } 40 }else { 41 cout << "No." << endl; 42 } 43 cout << "FINISH" << endl; 44 } 45 return 0; 46 }
参考博客:http://blog.csdn.net/lyhvoyage/article/details/18505997