| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
真没意思,照着题做就行了,都不用搞懂为什么我就完全按照题意写了一个,什么也没看,就ac了,等会再看看原理
#include <iostream>
#include <string>
#include<algorithm>
#include <stack>
using namespace std;
stack<string>backwards;
stack<string>forwards;
int main()
{
string text;
string current="http://www.acm.org/";
while(getline(cin,text))
{
if(text=="QUIT")break;
else if(text=="BACK")
{
if(backwards.empty())cout<<"Ignored"<<endl;
else
{
forwards.push(current);
current=backwards.top();
backwards.pop();
cout<<current<<endl;
}
}
else if(text=="FORWARD")
{
if(forwards.empty())cout<<"Ignored"<<endl;
else
{
backwards.push(current);
current=forwards.top();
forwards.pop();
cout<<current<<endl;
}
}
else
{
while(!forwards.empty())forwards.pop();
backwards.push(current);
current=text.substr(6);
cout<<current<<endl;
}
}
return 0;
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator