| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
Re:求代码?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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator