Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

Re:求代码?

Posted by moret at 2010-08-27 17:14:47 on Problem 1028
In Reply To:求代码? Posted by:mengsongshi at 2010-07-18 20:21:51
> 各位牛人,有谁用c做出来的,用到栈的,贴一下代码,我参考一下,这里谢谢了。
#include <stdio.h>
#include <string.h>

char backward[101][100];
char forward[101][100];
int cback,cfor;

int main()
{
	char command[100],url[100],curr[100]="http://www.acm.org/";
	while(scanf("%s",command)!=EOF)
	{
		if(!strcmp(command,"QUIT"))break;
		else if(!strcmp(command,"BACK"))
		{
			if(cback==0)
			{
				printf("Ignored\n");
				continue;
			}
			strcpy(forward[cfor++],curr);
			strcpy(curr,backward[--cback]);
			printf("%s\n",curr);
		}
		else if(!strcmp(command,"FORWARD"))
		{
			if(cfor==0)
			{
				printf("Ignored\n");
				continue;
			}
			strcpy(backward[cback++],curr);
			strcpy(curr,forward[--cfor]);
			printf("%s\n",curr);
		}
		else if(!strcmp(command,"VISIT"))
		{
			scanf("%s",url);
			strcpy(backward[cback++],curr);
			strcpy(curr,url);
			cfor=0;
			printf("%s\n",curr);
		}
	}
	return 0;
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator