首页 > 其他 > 详细

POJ 1028解答

时间:2016-04-12 14:13:19      阅读:265      评论:0      收藏:0      [点我收藏+]

#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");
}

}

}


}

 

}

POJ 1028解答

原文:http://www.cnblogs.com/guochen/p/5382360.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!