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 |
其实用一个数组就可以了。。。#include<iostream> #include<string> using namespace std; int main() { //设置数组初始状态 string str[100]={""}; str[0]="http://www.acm.org/"; int counter=0; int max=0; //读取指令 string mystr; cin>>mystr; //读取 QUIT 指令直接结束程序 //否则进入语法分析 while(mystr[0]!='Q') { //读取 VISIT 指令则访问网址 if(mystr[0]=='V') { //cout<<"info:VISIT"<<endl; counter++; max=counter; cin>>mystr; str[counter]=mystr; cout<<str[counter]<<endl; cin>>mystr; continue; } //读取 BACK 看是否在堆栈底部 //不在底部则执行 BACK 动作 if(mystr[0]=='B' && counter!=0) { //cout<<"info:BACK"<<endl; counter--; cout<<str[counter]<<endl; cin>>mystr; continue; } //在底部则拒绝执行 BACK 指令 if(mystr[0]=='B' && counter==0) { //cout<<"info:BACK"<<endl; cout<<"Ignored"<<endl; cin>>mystr; continue; } //读取 FORWARD 看是否在堆栈曾经的最前部 //不是则执行 FORWARD 指令 if(mystr[0]=='F' && max>=counter+1) { //cout<<"info:FORWARD"<<endl; counter++; cout<<str[counter]<<endl; cin>>mystr; continue; } //是则拒绝执行 FORWARD 指令 if(mystr[0]=='F' && max<counter+1) { //cout<<"info:FORWARD"<<endl; cout<<"Ignored"<<endl; cin>>mystr; continue; } } return(0); } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator