Ants.java
import java.io.*;
public class Ants {
int length;
int count;
while(true)
{
if(line == null) break;
data = line.split(" ");
int pos, posmax1 = -1;
int posmax2 = -1;
int d, d1, d2;
int maxd = 0;
int TYP = -2; // -2 = zadny, -1 = R, 1 = L, 0 = L i R
for(int i = 0; i < count; i++)
{
line = in.readLine();
ant = line.split(" ");
if(ant[1].equals("R"))
{
d = length-pos;
if(TYP == -1 || TYP == 0){
if(d > maxd){
maxd = d;
posmax1 = pos;
posmax2 = -1;
TYP = -1;
}
}else{
if(d > maxd){
maxd = d;
posmax1 = pos;
posmax2 = -1;
TYP = -1;
}
if(d == maxd){
posmax1 = pos;
TYP = 0;
}
}
}
else
{
d = pos;
if(TYP == 1 || TYP == 0){
if(d > maxd){
maxd = d;
posmax2 = pos;
posmax1 = -1;
TYP = 1;
}
}else{
if(d > maxd){
maxd = d;
posmax2 = pos;
posmax1 = -1;
TYP = 1;
}
if(d == maxd){
posmax2 = pos;
TYP = 0;
}
}
}
}
if(posmax1 == posmax2) posmax1 = -1;
if(posmax1
== -1) System.
out.
println("The last ant will fall down in "+maxd
+" seconds - started at "+posmax2
+"."); else if(posmax2
== -1) System.
out.
println("The last ant will fall down in "+maxd
+" seconds - started at "+posmax1
+"."); else{
int a,b;
if (posmax1 > posmax2){
a = posmax2;
b = posmax1;
}
else{
a = posmax1;
b = posmax2;
}
System.
out.
println("The last ant will fall down in "+maxd
+" seconds - started at "+a
+" and "+b
+"."); }
}
}
}