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

一次AC,虽然是个水题,但MARK一下

Posted by kamake at 2010-05-18 13:33:24 on Problem 1028
import java.util.Scanner;
import java.util.ArrayList;
/**
 *
 * @ACM 1028
 */
public class Main {
  public static String[] myorder={"VISIT","BACK","FORWARD","QUIT"};
  public static void main(String[] args)
  {
     ArrayList<String> order=new ArrayList<String>();
     Scanner scan=new Scanner(System.in);
     while(true)
     {
         String s=scan.next();
         if(s.equals(myorder[3]))
             break;
         else
             order.add(s);
     }
     String[] stack1=new String[order.size()];
     String[] stack2=new String[order.size()];
     int top1=0,top2=0,base1=0,base2=0;
     String web=null;//网站
     stack1[top1++]="http://www.acm.org/";
     for(int i=0;i<order.size();i++)
     {
         if(order.get(i).equals(myorder[0]))//如果是Visit
         {
             top2=0;
             base2=0;
             if(web!=null)
                 stack1[top1++]=web;
             web=order.get(i+1);
             i++;
             System.out.println(web);
         }
         else if(order.get(i).equals(myorder[1]))//如果是back
         {
             if(top1==base1)
                 System.out.println("Ignored");
             else
             {
                 if(web!=null)
                    stack2[top2++]=web;
                 web=stack1[--top1];
                 System.out.println(web);
             }
         }
         else if(order.get(i).equals(myorder[2]))
         {
             if(top2==base2)
                 System.out.println("Ignored");
             else
             {
                 if(web!=null)
                        stack1[top1++]=web;
                 web=stack2[--top2];
                 System.out.println(web);
             }
         }
     }
  }
}

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