import java.util.HashSet; import java.util.Iterator; import java.util.Scanner; import java.util.Set; import java.util.TreeSet; public class Main { public static void solution() { Scanner sc = new Scanner(System.in); int count = sc.nextInt(); count = count; sc.nextLine(); while (count != 0) { Set<String> files = new HashSet<>(); for (int i = 0; i < count; ++i) { files.add(sc.nextLine()); } Set<String> virusSet = new TreeSet<>(); Iterator<String> iterator = files.iterator(); while (iterator.hasNext()) { String file = iterator.next(); if (file.endsWith(".exe")) { String temp = file.substring(0, file.lastIndexOf(".exe")); if (files.contains(temp)) virusSet.add(file); } } for (String file : virusSet) System.out.println(file); count = sc.nextInt(); sc.nextLine(); } } public static void main(String[] args) { solution(); } } |
Double click to view unformatted code.