Source code for submission s1046

Go to diff to previous submission

Bugs.java

  1. /*
  2.  * To change this template, choose Tools | Templates
  3.  * and open the template in the editor.
  4.  */
  5. package bugs;
  6.  
  7.  
  8. import java.io.BufferedReader;
  9. import java.io.IOException;
  10. import java.io.InputStreamReader;
  11. import java.util.ArrayList;
  12. import java.util.Scanner;
  13. import org.omg.PortableInterceptor.SYSTEM_EXCEPTION;
  14.  
  15. /**
  16.  *
  17.  * @author student
  18.  */
  19. public class Bugs {
  20.  
  21. /**
  22.   * @param args the command line arguments
  23.   */
  24. public static void main(String[] args) throws IOException {
  25. Scanner sc = new Scanner(System.in);
  26.  
  27.  
  28. while (sc.hasNext()) {
  29. int rowCount = sc.nextInt();
  30. String text = sc.nextLine().trim();
  31.  
  32. for (int i = 0; i < rowCount; i++) {
  33. String row2 = sc.nextLine();
  34. String tmp = row2.replace(text, "");
  35. System.out.println(tmp);
  36. }
  37. }
  38.  
  39. }
  40. }
  41.  

Diff to submission s966

Bugs.java

--- c4.s966.cteam124.bugs.java.0.Bugs.java
+++ c4.s1046.cteam124.bugs.java.0.Bugs.java
@@ -10,4 +10,6 @@
 import java.io.InputStreamReader;
 import java.util.ArrayList;
+import java.util.Scanner;
+import org.omg.PortableInterceptor.SYSTEM_EXCEPTION;
 
 /**
@@ -21,27 +23,16 @@
      */
     public static void main(String[] args) throws IOException {
-        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
-        StringBuffer row = new StringBuffer(br.readLine());
-    
-        ArrayList<String> rows = new ArrayList<String>();   
+        Scanner sc = new Scanner(System.in);
 
-        while(row.length()>0) {
-            Integer whiteChar = row.toString().indexOf(" ");
-            
-            int rowCount = Integer.valueOf(row.substring(0, whiteChar));
-            String text = row.substring(whiteChar+1, row.length());
-            
+        
+        while (sc.hasNext()) {            
+            int rowCount = sc.nextInt();
+            String text = sc.nextLine().trim();
             
-                         
             for (int i = 0; i < rowCount; i++) {
-                String row2 = br.readLine();
+                String row2 = sc.nextLine();
                 String tmp = row2.replace(text, "");
-                rows.add(tmp);
+                System.out.println(tmp);
             }
-            row = new StringBuffer(br.readLine());
-        }
-        
-        for (String r : rows) {
-            System.out.println(r);
         }