10/08/2013

10963 - The Swallowing Ground - Java

 import java.io.BufferedReader;  
 import java.io.IOException;  
 import java.io.InputStream;  
 import java.io.InputStreamReader;  
 import java.util.StringTokenizer;  
 public class SwallowingGround {  
      public static void main(String[] args) throws IOException {  
           Reader.init(System.in);  
           int noOfCases = Reader.nextInt();  
           int noOfColumns;  
           int x;  
           int y;  
           int maxGap;  
           boolean tempVal;  
           while((noOfCases--) > 0) {  
                noOfColumns = Reader.nextInt();  
                x = Reader.nextInt();  
                y = Reader.nextInt();  
                maxGap = Math.abs(x - y);  
                //System.out.println("DEBUG: " + Math.abs(x-y));  
                tempVal = true;  
                while((noOfColumns --) > 1) {  
                     x = Reader.nextInt();  
                     y = Reader.nextInt();  
                     //System.out.println("DEBUG: " + Math.abs(x-y));  
                     if(Math.abs(x - y) != maxGap) {  
                          tempVal = false;  
                          //break;  
                     }  
                }  
                if(tempVal) System.out.println("yes");  
                else System.out.println("no");  
                if(noOfCases != 0) System.out.println("");  
                //tempVal = true;  
           }  
      }  
 }  
 /** Class for buffered reading int and double values */  
 /** http://www.cpe.ku.ac.th/~jim/java-io.html */  
 class Reader {  
      static BufferedReader reader;  
      static StringTokenizer tokenizer;  
      /** call this method to initialize reader for InputStream */  
      static void init(InputStream input) {  
           reader = new BufferedReader(new InputStreamReader(input));  
           tokenizer = new StringTokenizer("");  
      }  
      /** get next word */  
      static String next() throws IOException {  
           while ( ! tokenizer.hasMoreTokens() ) {  
                //TODO add check for eof if necessary  
                tokenizer = new StringTokenizer(reader.readLine());  
           }  
           return tokenizer.nextToken();  
      }  
      static int nextInt() throws IOException {  
           return Integer.parseInt( next() );  
      }  
      static double nextDouble() throws IOException {  
           return Double.parseDouble( next() );  
      }  
 }  

No comments:

Post a Comment