Advertisement
Slyke

H231

Jul 28th, 2013
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.40 KB | None | 0 0
  1. import java.util.*; public class H231 {public static void main (String[] args) {while (JPL.test()) {
  2.  
  3. ////////////////////////////// PROBLEM STATEMENT //////////////////////////////
  4. // Given a string, print true if the number of appearances of "is" anywhere  //
  5. // in the string is equal to the number of appearances of "not" anywhere in  //
  6. // the string (case sensitive).                                              //
  7. //   "This is not" -> false                                                  //
  8. //   "This is notnot" -> true                                                //
  9. //   "noisxxnotyynotxisi" -> true                                            //
  10. ///////////////////////////////////////////////////////////////////////////////
  11.  
  12.   // >>>>>> Your Java Code Fragment starts here <<<<<<
  13.  
  14.   Scanner kb=new Scanner(System.in);
  15.  
  16.   String toSearch=kb.nextLine();
  17.   int strLength=toSearch.length();
  18.  
  19.   int isCount=0;
  20.   int notCount=0;
  21.  
  22.   for (int i=1;i<strLength;i++) {
  23.     if (toSearch.charAt(i)=='s' && toSearch.charAt(i-1)=='i') {
  24.       isCount++;
  25.     }
  26.     if (i>=2) {
  27.       if (toSearch.charAt(i)=='t' && toSearch.charAt(i-1)=='o' && toSearch.charAt(i-2)=='n') {
  28.         notCount++;
  29.       }
  30.     }
  31.   }
  32.  
  33.   if (isCount == notCount) {
  34.     System.out.print(true);
  35.   } else {
  36.     System.out.print(false);
  37.   }
  38.  
  39.   // >>>>>> Your Java Code Fragment ends here <<<<<<
  40. }}}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement