POJ 1028解答

#include <iostream>
#include <cstdio>
#include <cmath>
#include <stack>
#include <string>

using namespace std;

int main()
{
char command[16];
char url[71];

stack<string> forwardStack;
stack<string> backStack;

string curUrl = "http://www.acm.org/";
backStack.push(curUrl);

while (true)
{
gets_s(command);

if (strcmp(command, "QUIT") == 0)
{
break;
}
else if (strcmp(command, "VISIT") == 0)
{
gets_s(url);
curUrl = url;
backStack.push(curUrl);

puts(curUrl.c_str());
puts("\n");
}
else if (strcmp(command, "BACK") == 0)
{
if (backStack.empty())
{
puts("Ignored\n");
}
else
{
forwardStack.push(curUrl);
backStack.pop();
if (!backStack.empty())
{
curUrl = backStack.top();
puts(curUrl.c_str());
puts("\n");
}
else
{
puts("Ignored\n");
}

}

}
else if (strcmp(command, "FORWARD") == 0)
{
if (forwardStack.empty())
{
puts("Ignored\n");
}
else
{
backStack.push(curUrl);
forwardStack.pop();
if (!forwardStack.empty())
{
curUrl = forwardStack.top();
puts(curUrl.c_str());
puts("\n");
}
else
{
puts("Ignored\n");
}

}

}


}

}

原文地址:https://www.cnblogs.com/guochen/p/5382360.html