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

纪念一下~~~~~~~话说c++的引用参数好给力啊

Posted by woshi123life at 2012-12-12 15:26:50 on Problem 1028
#include <stdio.h>
#include <string.h>
#define maxn 110
typedef struct
{
    char page[75];
}element;
void  pop(int& top,element *stack)
{

     printf("%s\n",stack[top].page);
     (top)--;
}
void push(char  *c,element *stack,int& top)
{
     strcpy(stack[++(top)].page,c);
}
int main()
{
    element stack_f[maxn],stack_b[maxn];
    int top,top1;
    char CurrentPage[75];
    char homepage[]={"http://www.acm.org/"};
    char s[75];
    strcpy(CurrentPage,homepage);
    element t;
    top=top1=-1;
    while(~scanf("%s",s))
    {

       if(!strcmp(s,"VISIT"))
       {
           scanf("%s",t.page);
           printf("%s\n",t.page);
           push(CurrentPage,stack_b,top1);
           strcpy(CurrentPage,t.page);
           top=-1;
       }
       else if(!strcmp(s,"BACK"))
       {        if(top1==-1)
                {printf("Ignored\n");
                 continue ;}
           push(CurrentPage,stack_f,top);
           strcpy(CurrentPage,stack_b[top1].page);
           pop(top1,stack_b);
       }
       else if(!strcmp(s,"FORWARD"))
       {  if(top==-1)
          {printf("Ignored\n");
                 continue ;}
           push(CurrentPage,stack_b,top1);
           strcpy(CurrentPage,stack_f[top].page);
           pop(top,stack_f);
       }
       else if(!strcmp(s,"QUIT"))
             break;
    }
       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