import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.lang.Math; public class Threesetreducer { public static void main(String args[]) { try { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String input; String index = null; String currentIndex = null; double currentCount1 = 0; double currentCount2 = 0; double currentCount3 = 0; while ((input = br.readLine()) != null) { try { String[] fields = input.split("\t"); key = fields[0]; double val1 = Double.parseDouble(fields[1]); double val2 = Double.parseDouble(fields[2]); double val3 = Double.parseDouble(fields[3]); // We have sorted input, so check if we have the same index if (currentIndex != null && currentIndex.equals(index)){ currentCount1 += val1; currentCount2 += val2; currentCount3 += val3; } else { // the index has changed if (currentIndex != null) { ' System.out.println(currentIndex + "\t" + currentCount1 + "\t" +Math.sqrt(currentCount2)+ "\t" + Math.sqrt(currentCount3)); } currentIndex = index; currentCount1 = val1; currentCount2 = val2; currentCount3 = val3; } } catch (NumberFormatException e) { continue; } } if (currentIndex != null && currentIndex.equals(index)) { System.out.println(currentIndex + "\t" + currentCount1 + "\t" + Math.sqrt(currentCount2) + "\t" + Math.sqrt(currentCount3)); } } catch(IOException io) { io.printStackTrace(); } } }