Poj Solution 2328

http://poj.org/problem?id=2328

    import java.util.*;  
      
    public class Main {  
      
        public static void main(String[] args) {  
              
            Scanner cin = new Scanner(System.in);  
          
            List guess = new ArrayList();  
           List response = new ArrayList();  
             
           while(cin.hasNext())  
           {  
               String guessNum = cin.nextLine();  
               if(guessNum.equals("0"))  
                   break;  
              String result = cin.nextLine();  
                
              guess.add(guessNum);  
              response.add(result);  
                 
               if(!result.equals("right on"))  
                   continue;  
                 
               else  
               {  
                   int honest = check(guess, response);  
                   if(honest == 1)  
                       System.out.println("Stan may be honest");  
                   else  
                       System.out.println("Stan is dishonest");  
                   guess.clear();  
                   response.clear();  
               }  
           }  
       }  
         
       private static int check(List guess, List response)  
       {  
           int honest = 1;  
             
           int lower = 0;  
           int upper = 11;  
             
           for(int i = 0; i < guess.size(); i++)  
           {  
               int g = Integer.valueOf((String)guess.get(i)).intValue();  
               String r = (String)response.get(i);  
                 
               if(r.equals("too high"))  
               {  
                   if(g <= lower)  
                   {  
                       honest = -1;  
                       break;  
                  }  
                   if(g < upper)  
                   {  
                       upper = g;  
                   }  
                     
               }  
               if(r.equals("too low"))  
               {  
                   if(g >= upper)  
                   {  
                       honest = -2;  
                       break;  
                   }  
                   if(g > lower)  
                   {  
                       lower = g;  
                   }  
               }  
                 
               if(r.equals("right on"))  
               {  
                   if(upper <= g || lower >= g || upper < lower)  
                   {  
                       honest = -3;  
                       break;  
                   }  
               }  
           }  
             
           return honest;  
       }  
     
   }  

											
This entry was posted in poj. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *