fork download
  1. import java.io.BufferedReader;
  2. import java.io.InputStreamReader;
  3. import java.io.IOException;
  4. import java.util.Set;
  5. import java.util.TreeSet;
  6.  
  7. public class Main {
  8. public static void main(String[] args) throws IOException {
  9. String currentMovie = null;
  10. Set<String> tagsSet = new TreeSet<>();
  11. String line;
  12.  
  13. while ((line = br.readLine()) != null) {
  14. line = line.trim();
  15. if (line.isEmpty()) continue;
  16.  
  17. String[] parts = line.split("\t", 2);
  18. String movieId = parts[0];
  19. String tag = parts[1];
  20.  
  21. if (!movieId.equals(currentMovie)) {
  22. if (currentMovie != null) {
  23. System.out.println(currentMovie + "\t" + String.join(",", tagsSet));
  24. }
  25. currentMovie = movieId;
  26. tagsSet.clear();
  27. }
  28. tagsSet.add(tag);
  29. }
  30. if (currentMovie != null) {
  31. System.out.println(currentMovie + "\t" + String.join(",", tagsSet));
  32. }
  33. }
  34. }
  35.  
Success #stdin #stdout 0.09s 54988KB
stdin
Standard input is empty
stdout
Standard output is empty