LightOJ 1113 - Discover the Web
//Next Codeforces Round #354 (Div. 2)
#include<bits/stdc++.h>
//#include<cstdio>
//#include<iostream>
//#include<algorithm>
//#include<vector>
//#include<cstring>
//#include<cmath>
//#include<map>
using namespace std;
#define fast ios_base::sync_with_stdio(false)
#define bfast cin.tie(0)
#define outs(x) cout << x << " "
#define outn(x) cout << x << "\n"
#define sf scanf
#define pf printf
#define nl puts("")
#define psb push_back
//#define i64 long long
#define fixed "http://www.lightoj.com/"
typedef long long LL;
typedef vector<int>vii;
typedef vector<LL>vll;
typedef stack<string>stkstr;
typedef queue<string>qustr;
int main()
{
fast;
//freopen("out.txt" , "w" , stdout);
int t , tc=0;
cin >> t;
while(t--)
{
cout << "Case " << ++tc << ":\n";
stkstr bs, fs;
string command, url;
bs.push(fixed);
while(cin >> command){
if(command == "VISIT")
{
cin >> url;
bs.push(url);
cout << url << "\n";
if(!fs.empty())
{
while(!fs.empty())
{
fs.pop();
}
}
}
else if(command == "BACK")
{
fs.push(bs.top());
bs.pop();
if(bs.empty())
{
cout << "Ignored" << "\n";
bs.push(fs.top());
fs.pop();
}
else
{
cout << bs.top() << "\n";
}
}
else if(command == "FORWARD")
{
if(fs.empty())
{
cout << "Ignored"<< "\n";
}
else
{
cout << fs.top() << "\n";
bs.push(fs.top());
fs.pop();
}
}
else if(command == "QUIT")
{
break;
}
}
}
return 0;
}
#include<bits/stdc++.h>
//#include<cstdio>
//#include<iostream>
//#include<algorithm>
//#include<vector>
//#include<cstring>
//#include<cmath>
//#include<map>
using namespace std;
#define fast ios_base::sync_with_stdio(false)
#define bfast cin.tie(0)
#define outs(x) cout << x << " "
#define outn(x) cout << x << "\n"
#define sf scanf
#define pf printf
#define nl puts("")
#define psb push_back
//#define i64 long long
#define fixed "http://www.lightoj.com/"
typedef long long LL;
typedef vector<int>vii;
typedef vector<LL>vll;
typedef stack<string>stkstr;
typedef queue<string>qustr;
int main()
{
fast;
//freopen("out.txt" , "w" , stdout);
int t , tc=0;
cin >> t;
while(t--)
{
cout << "Case " << ++tc << ":\n";
stkstr bs, fs;
string command, url;
bs.push(fixed);
while(cin >> command){
if(command == "VISIT")
{
cin >> url;
bs.push(url);
cout << url << "\n";
if(!fs.empty())
{
while(!fs.empty())
{
fs.pop();
}
}
}
else if(command == "BACK")
{
fs.push(bs.top());
bs.pop();
if(bs.empty())
{
cout << "Ignored" << "\n";
bs.push(fs.top());
fs.pop();
}
else
{
cout << bs.top() << "\n";
}
}
else if(command == "FORWARD")
{
if(fs.empty())
{
cout << "Ignored"<< "\n";
}
else
{
cout << fs.top() << "\n";
bs.push(fs.top());
fs.pop();
}
}
else if(command == "QUIT")
{
break;
}
}
}
return 0;
}
Comments
Post a Comment