Source code for submission s1018

Go to diff to previous submission

Mosquito.java

  1. /*
  2.  * To change this template, choose Tools | Templates
  3.  * and open the template in the editor.
  4.  */
  5. package mosquito;
  6.  
  7. import java.util.Scanner;
  8.  
  9. /**
  10.  *
  11.  * @author student
  12.  */
  13. public class Mosquito {
  14.  
  15. /**
  16.   * @param args the command line arguments
  17.   */
  18. public static void main(String[] args)throws Exception {
  19. Scanner sc = new Scanner(System.in);
  20. int[] a = new int[7];
  21. int pom = 0;
  22.  
  23. while (sc.hasNextInt()) {
  24. a[0] = sc.nextInt();
  25. a[1] = sc.nextInt();
  26. a[2] = sc.nextInt();
  27. a[3] = sc.nextInt();
  28. a[4] = sc.nextInt();
  29. a[5] = sc.nextInt();
  30. a[6] = sc.nextInt();
  31.  
  32. if (a[6] > 0) {
  33. for (int i = 0; i < a[6]; i++) {
  34. pom = a[0];
  35. if (a[5] > 0) {
  36. a[0] = Math.round(a[1] / a[5]);
  37. } else {
  38. a[0] = a[1];
  39. }
  40. if (a[4] > 0) {
  41. a[1] = Math.round(a[2] / a[4]);
  42. } else {
  43. a[1] = a[2];
  44. }
  45. a[2] = pom * a[3];
  46.  
  47. }
  48. }
  49.  
  50. System.out.println(a[0]);
  51. }
  52.  
  53.  
  54. }
  55. }
  56.  

Diff to submission s1002

Mosquito.java

--- c4.s1002.cteam124.mosquito.java.0.Mosquito.java
+++ c4.s1018.cteam124.mosquito.java.0.Mosquito.java
@@ -1,4 +1,8 @@
-import java.util.ArrayList;
-import java.util.List;
+/*
+ * To change this template, choose Tools | Templates
+ * and open the template in the editor.
+ */
+package mosquito;
+
 import java.util.Scanner;
 
@@ -12,16 +16,18 @@
      * @param args the command line arguments
      */
-    public static void main(String[] args) {
+    public static void main(String[] args)throws Exception {
         Scanner sc = new Scanner(System.in);
-        String res = sc.nextLine();
-        List<Integer> result = new ArrayList<Integer>();
         int[] a = new int[7];
         int pom = 0;
-        while (!"".equals(res)) {
-            String[] ress = res.split(" ");
-            for (int i = 0; i < ress.length; i++) {
-                a[i] = Integer.parseInt(ress[i]);
-            }
-            try {
+            
+            while (sc.hasNextInt()) {
+                a[0] = sc.nextInt();
+                a[1] = sc.nextInt();
+                a[2] = sc.nextInt();
+                a[3] = sc.nextInt();
+                a[4] = sc.nextInt();
+                a[5] = sc.nextInt();
+                a[6] = sc.nextInt();
+                
                 if (a[6] > 0) {
                     for (int i = 0; i < a[6]; i++) {
@@ -41,15 +47,9 @@
                     }
                 }
-            } catch(ArithmeticException ex) {
-                System.err.println(ex.toString());
+                
+                System.out.println(a[0]);
             }
-            result.add(a[0]);
-            res = sc.nextLine();
-        }
-        for (Integer string : result) {
-            System.out.println(string);
-        }
 
 
     }
-}
\ No newline at end of file
+}