Time Limit: 1000MS | Memory Limit: 10000K | |
Total Submissions: 16142 | Accepted: 7046 |
本题很简单,就是栈的运用,不过由于本人以前从未用过c++所以字符串对我来说比较难处理。这是本人第一次用c++来实现,算是一种进步吧!
代码:
1 #include<iostream>
2 #include<stack>
3 #include<string>
4 using namespace std;
5 int main()
6 {
7 stack<string> st1;
8 stack<string> st2;
9 string str1="http://www.acm.org/";
10 string str2;
11 int mark;
12 char a[10];char s[50];
13 while(scanf("%s",a)!=EOF)
14 {
15 mark=0;
16 switch(a[0])
17 {
18 case 'Q':mark=1;break;
19 case 'V':
20 scanf("%s",s); st1.push(str1); str1=s; cout<<str1<<endl;while(!st2.empty())st2.pop();break;
21 case 'B':if(!st1.empty()) {str2=st1.top();st1.pop();cout<<str2<<endl;st2.push(str1);str1=str2;}else cout<<"Ignored"<<endl;break;
22 case 'F':if(!st2.empty()) {str2=st2.top();st2.pop();cout<<str2<<endl;st1.push(str1);str1=str2;}else cout<<"Ignored"<<endl;break;
23 }
24 if(mark)
25 break;
26 }
27 return 0;
28 }
29
30