|
|
back to boardHelpPlease (Java) Posted by Testme 18 Mar 2014 00:37 What is wrong with mycode? it is working in mycomputer but failing in test2 import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.Scanner; /** * Created by sherxon on 3/17/14. */ public class Biathlon { public static void main(String[] args) { Scanner in = new Scanner(System.in); int n=Integer.parseInt(in.nextLine()); String s, name, time; Double min, sec; int j=0; List<String> a= new ArrayList(); ArrayList<Double> b= new ArrayList(); int thirty=0; for (int i = 0; i <n ; i++) { s = in.nextLine(); name=s.split(" ")[0]; sec=Double.parseDouble(s.split(" ")[1].split(":")[1])+60*(Double.parseDouble(s.split(" ")[1].split(":")[0])); sec+=thirty; //System.out.println(sec); double eachsec=0.0; double eachsecs=0.0; boolean bl=true; for (int k = 0; k<a.size() ; k++) { // System.out.println(sec-thirty + " " + (b.get(k)-eachsec) + " " +(sec) + " " + b.get(k)); if(sec-thirty<b.get(k)-eachsec&&sec<b.get(k)){ b.remove(k); a.remove(k); k--; } eachsec+=30; } for (int k = 0; k <a.size() ; k++) { if(sec-thirty>b.get(k)-eachsecs){ bl=false; } eachsecs+=30; } if(bl){ a.add(name); b.add(sec); } thirty+=30; } Collections.sort(a); System.out.println(a.size()); for (int i = 0; i <a.size() ; i++) { System.out.println(a.get(i)); } } } |
|
|