Source code for submission s1113

Go to diff to previous submission

Ants.java

  1.  
  2. import java.io.BufferedReader;
  3.  
  4. /*
  5.  * To change this template, choose Tools | Templates
  6.  * and open the template in the editor.
  7.  */
  8. import java.io.IOException;
  9. import java.io.InputStreamReader;
  10. import java.util.Arrays;
  11. import java.util.LinkedList;
  12. import java.util.StringTokenizer;
  13.  
  14.  
  15.  
  16. /**
  17.  *
  18.  * @author cteam022
  19.  */
  20. public class Ants {
  21.  
  22.  
  23. /**
  24.   * @param args the command line arguments
  25.   */
  26. public static void main(String[] args) throws IOException {
  27. Ants g = new Ants();
  28. while(true){g.uloha();}
  29. }
  30.  
  31. void uloha() throws IOException{
  32. if(!input.ready()){System.exit(0);}
  33. st = new StringTokenizer(input.readLine());
  34. int L = Integer.valueOf(st.nextToken());
  35. int A = Integer.valueOf(st.nextToken());
  36.  
  37. int[] pozic = new int[A];
  38. boolean[] smery = new boolean[L+5];
  39.  
  40. int pravy = 0;
  41. int levy = 0;
  42.  
  43. int cas1 = Integer.MAX_VALUE;
  44. int mravenec1 = Integer.MAX_VALUE;
  45.  
  46. int cas2 = -1;
  47. int mravenec2 = -1;
  48.  
  49. for(int i = 0; i<A; i++){
  50. st = new StringTokenizer(input.readLine());
  51. int pozice = Integer.valueOf(st.nextToken());
  52. String s = st.nextToken();
  53. boolean smer = (s.equals("R"));
  54. pozic[i] = pozice;
  55.  
  56. //smery[i] = smer;
  57.  
  58. if(smer){
  59. pravy++;
  60. }else{
  61. levy++;
  62. }
  63.  
  64. if(pozice < cas1 && smer ) {
  65. cas1 = pozice;
  66. mravenec1 = i;
  67. }
  68.  
  69. if(pozice > cas2 && smer==false ) {
  70. cas2 = pozice;
  71. mravenec2 = i;
  72. }
  73.  
  74.  
  75. }
  76.  
  77. Arrays.sort(pozic);
  78.  
  79. if(cas1 == Integer.MAX_VALUE)
  80. cas1 = -1;
  81. else
  82. cas1 = L - cas1;
  83.  
  84. if(cas1 == cas2){
  85. System.out.println("The last ant will fall down in " + cas1 + " seconds - started at " + pozic[levy-1] + " and "+pozic[levy]+".");
  86. }else{
  87.  
  88. if(cas1 > cas2){
  89. System.out.println("The last ant will fall down in " + cas1 + " seconds - started at " +pozic[levy]+".");
  90. }else{
  91. System.out.println("The last ant will fall down in " + cas2 + " seconds - started at " +pozic[levy-1]+".");
  92. }
  93.  
  94. }
  95.  
  96. }
  97.  
  98.  
  99.  
  100. }
  101.  

Diff to submission s1102

Ants.java

--- c4.s1102.cteam022.ants.java.0.Ants.java
+++ c4.s1113.cteam022.ants.java.0.Ants.java
@@ -85,11 +85,11 @@
         
         if(cas1 == cas2){
-            System.out.println("The last ant will fall down in " + cas1 + " seconds - started at " + pozic[levy-1] + " and "+pozic[levy]);
+            System.out.println("The last ant will fall down in " + cas1 + " seconds - started at " + pozic[levy-1] + " and "+pozic[levy]+".");
         }else{
         
             if(cas1 > cas2){
-                System.out.println("The last ant will fall down in " + cas1 + " seconds - started at " +pozic[levy]);
+                System.out.println("The last ant will fall down in " + cas1 + " seconds - started at " +pozic[levy]+".");
             }else{
-                System.out.println("The last ant will fall down in " + cas2 + " seconds - started at " +pozic[levy-1]);
+                System.out.println("The last ant will fall down in " + cas2 + " seconds - started at " +pozic[levy-1]+".");
             }