zoj1061 Web Navigation

  1. //zoj1061 Web Navigation

  2. //Accepted 1061 C++ 00:00.03 852K

  3. #include

  4. #include

  5. #include

  6. using namespace std;

  7.  

  8. void solve()

  9. {

  10.        char t[10],s[101][71]={"http://www.acm.org/"};

  11.        int cnt=1,pos=0;

  12.        while (1){

  13.               cin >> t;

  14.               if (strcmp(t,"QUIT")==0) break;

  15.               if (strcmp(t,"VISIT")==0){

  16.                      pos++;

  17.                      cin >> s[pos];

  18.                      cout << s[pos] << endl;

  19.                      cnt = pos+1;

  20.               }

  21.               if (strcmp(t,"BACK")==0){

  22.                      pos--;

  23.                      if (pos<0) {

  24.                             pos = 0;

  25.                             cout << "Ignored" << endl;

  26.                      }

  27.                      else cout << s[pos] << endl;

  28.               }

  29.               if (strcmp(t,"FORWARD")==0){

  30.                      pos++;

  31.                      if (pos

  32.                      else {

  33.                             pos = cnt-1;

  34.                             cout << "Ignored" << endl;

  35.                      }

  36.               }

  37.        }

  38. }

  39.  

  40. int main()

  41. {

  42. #ifdef ONLINE_JUDGE

  43. #else

  44.        freopen("1061.txt","r",stdin);

  45. #endif

  46.        int n;

  47.        while (cin >> n)

  48.               for (int i=0; i

  49.                      if (i>0) cout << endl;

  50.                      solve();

  51.               }

  52. #ifdef ONLINE_JUDGE

  53. #else

  54.        fclose(stdin);

  55. #endif

  56.        return 0;

  57. }  

你可能感兴趣的:(ZOJ)