06/10/2013

10324 - Zeros and Ones - Java

 package org.goro.uva.m;  
 import java.io.*;  
 import java.util.*;  
 public class ZerosAndOnes {  
      public static void main(String[] args) throws Exception {  
           InputStreamReader isr = new InputStreamReader(System.in);  
           BufferedReader br = new BufferedReader(isr);  
           StringBuilder sb = new StringBuilder("");  
           int testCase = 1;  
           String line;  
           while ((line = br.readLine()) != null) {  
                sb.append("Case ").append(testCase).append(":\n");  
                testCase++;  
                int noOfCases = Integer.parseInt(br.readLine());  
                for (int j = 0; j < noOfCases; j++) {  
                     String[] str = br.readLine().split(" ");  
                     int val1 = Integer.parseInt(str[0]);  
                     int val2 = Integer.parseInt(str[1]);  
                     if (val1 > val2) {  
                          val1 ^= val2;  
                          val2 ^= val1;  
                          val1 ^= val2;  
                     }  
                     boolean isValid = true;  
                     if (val1 != val2) {  
                          for (int i = val1; i < val2; i++) {  
                               if (line.charAt(i) != line.charAt(i + 1)) {  
                                    isValid = false;  
                                    break;  
                               }  
                          }  
                     }  
                     if (isValid)  
                          sb.append("Yes\n");  
                     else   
                          sb.append("No\n");            
                }  
           }  
           System.out.print(sb);  
      }  
 }  

1 comment:


  1. A Cobol programmer made so much money doing Y2K remediation that he was able to have himself cryogenically frozen when he died. One day in the future, he was unexpectedly resurrected.

    When he asked why he was unfrozen, he was told:

    "It's the year 9999 - and you know Cobol"

    ReplyDelete