poj1028 Web Navigation

Accepted 360K 16MS G++ 700B

 

 1 #include<stdio.h>
 2 #include<string.h>
 3 char fs[100][71],bs[100][71];
 4 int ftop,btop;
 5 int main()
 6 {
 7     char a[8],cur[71];
 8     strcpy(cur,"http://www.acm.org/");
 9     while(scanf("%s",a),strcmp(a,"QUIT")){
10         if(!strcmp(a,"VISIT")){
11             strcpy(bs[btop++],cur);
12             scanf("%s",cur);
13             puts(cur);
14             ftop=0;
15         }
16         else if(!strcmp(a,"FORWARD")){    
17             if(ftop){
18                 strcpy(bs[btop++],cur);
19                 strcpy(cur,fs[--ftop]);
20                 puts(cur);
21             }
22             else puts("Ignored");
23         }
24         else if(!strcmp(a,"BACK")){
25             if(btop){
26                 strcpy(fs[ftop++],cur);
27                 strcpy(cur,bs[--btop]);
28                 puts(cur);
29             }
30             else puts("Ignored");
31         }
32     }
33     return 0;
34 }
Accepted 688K 32MS G++ 564B
 1 #include<iostream>
 2 using namespace std;
 3 string fs[100],bs[100];
 4 int ftop,btop;
 5 int main()
 6 {
 7     string a,cur;
 8     cur="http://www.acm.org/";
 9     while(cin>>a,a!="QUIT"){
10         if(a=="VISIT"){
11             bs[btop++]=cur;
12             cin>>cur;
13             cout<<cur<<endl;
14             ftop=0;
15         }
16         else if(a=="FORWARD"){    
17             if(ftop){
18                 bs[btop++]=cur;
19                 cur=fs[--ftop];
20                 cout<<cur<<endl;
21             }
22             else cout<<"Ignored\n";
23         }
24         else if(a=="BACK"){
25             if(btop){
26                 fs[ftop++]=cur;
27                 cur=bs[--btop];
28                 cout<<cur<<endl;
29             }
30             else cout<<"Ignored\n";
31         }
32     }
33     return 0;
34 }

posted on 2012-08-07 16:23  小花熊  阅读(193)  评论(0编辑  收藏  举报

导航