zoukankan      html  css  js  c++  java
  • POJ 1028 Web Navigation 题解

    考查代码能力的题目。也能够说是算法水题,呵呵。

    推荐新手练习代码能力。

    要添加难度就使用纯C实现一下stack,那么就有点难度了,能够使用数组模拟环形栈。做多了,我就直接使用STL了。


    #include <stdio.h>
    #include <iostream>
    #include <stack>
    #include <string>
    using namespace std;
    
    int main()
    {
    	stack<string> forward;
    	stack<string> backward;
    	string cur = "http://www.acm.org/";
    	string cmd;
    
    	while (cin>>cmd)
    	{
    		if (cmd == "QUIT") break;
    
    		if (cmd == "VISIT")
    		{
    			backward.push(cur);
    			cin>>cur;
    			puts(cur.c_str());
    			forward = stack<string>();
    		}
    		else if (cmd == "BACK")
    		{
    			if (backward.empty())
    			{
    				puts("Ignored");
    			}
    			else
    			{
    				forward.push(cur);
    				cur = backward.top();
    				backward.pop();
    				puts(cur.c_str());
    			}
    		}
    		else if (cmd == "FORWARD")
    		{
    			if (forward.empty())
    			{
    				puts("Ignored");
    			}
    			else
    			{
    				backward.push(cur);
    				cur = forward.top();
    				forward.pop();
    				puts(cur.c_str());
    			}
    		}
    	}
    	return 0;
    }



  • 相关阅读:
    Manacher-模版题poj3974 hdu3068
    拓展kmp(带注释版)
    颓の第17周
    php 递归遍历目录带缩进
    php 递归遍历目录
    php session
    apache主机配置
    php环境配置的检测方法
    php 变量
    php MVC
  • 原文地址:https://www.cnblogs.com/mengfanrong/p/4363672.html
Copyright © 2011-2022 走看看