POJ 1028.Web Navigation

一道经典的模拟题目,比较麻烦,不确定按照现在的水平还能不能做出来了。。。

这个题主要是需要“指针”(不是平常说的那个指针),一个指向当前,一个指向去哪

题目大意:有几个网页,题目给出向前向后的操作,要求输出所到达的那个网页

题目链接

#include <iostream>
#include <cstring>
using namespace std;
int main(void)
{
	char s[1005][105];
	s[0][0] = 'h';
	s[0][1] = 't'; 
	s[0][2] = 't';
	s[0][3] = 'p';
	s[0][4] = ':';
	s[0][5] = '/';
	s[0][6] = '/';
	s[0][7] = 'w';
	s[0][8] = 'w';
	s[0][9] = 'w';
	s[0][10] = '.';
	s[0][11] = 'a';
	s[0][12] = 'c';
	s[0][13] = 'm';
	s[0][14] = '.';
	s[0][15] = 'o';
	s[0][16] = 'r';
	s[0][17] = 'g';
	s[0][18] = '/';
	
//	printf("%s",s[0]);
	char temp[105];
	//需要两个“指针” 一个指向当前 一个指向要去哪 
	int i=0;
	int j=0;
	while(1)//模拟执行完毕 开始改进输入 
	{
		gets(temp);
		if(temp[0]=='Q')	break;
		if(temp[0]=='V')
		{
		//	printf("-------%s\n",temp);
			for(int k=6;k<strlen(temp);k++)
			{
				printf("%c",temp[k]);
			 } 
			 printf("\n");
			i = j;
			strcpy(s[++i],temp); 
			j++;
		//	i = j;
		}
		if(temp[0]=='F')
		{
			j++;
			if(j>i)
			{
				printf("Ignored\n");
				 j = i; 
				continue;
			}
		//	printf("-------%s\n",s[j]); 
			if(j==0)	printf("%s",s[0]);
			else
				for(int k=6;k<strlen(s[j]);k++)
				{
					printf("%c",s[j][k]);
				}
			printf("\n");
		}
		if(temp[0]=='B')
		{
			j--;
		//	i = j;
			if(j<0)
			{
				printf("Ignored\n");
				j = 0;
				continue;
			}
			//printf("-------%s\n",s[j]);
			if(j==0)	printf("%s",s[0]);
			else
				for(int k=6;k<strlen(s[j]);k++)
				{
					printf("%c",s[j][k]);
				}
			printf("\n");
		//	i = j;//清空掉剩余的? 
		}
		if(temp[0]=='C')
		{
			for(int p=0;p<=i;p++)
			{
				printf("Check:%s\n",s[p]);
			}
		}
	}
} 	

猜你喜欢

转载自blog.csdn.net/curiousliu/article/details/81150872
今日推荐