fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone
  9. {
  10. public static void main (String[] args) throws java.lang.Exception
  11. {
  12.  
  13. Scanner sc = new Scanner(System.in);
  14. List<String> lines = new ArrayList<String>();
  15. while (sc.hasNextLine()) {
  16. lines.add(sc.nextLine());
  17. }
  18. Collections.sort(lines);
  19. Map<String,String[]> keys = new HashMap<String,String[]>();
  20. Map<String,Integer> counts = new HashMap<String,Integer>();
  21. for (String s : lines) {
  22. String[] tt = s.split(" ");
  23. String user = tt[1];
  24. String page = tt[2];
  25. if (!keys.containsKey(user)) {
  26. keys.put(user, new String[] {null, null, page});
  27. continue;
  28. }
  29. String[] pages = keys.get(user);
  30. pages[0] = pages[1];
  31. pages[1] = pages[2];
  32. pages[2] = page;
  33. if (pages[0] == null) {
  34. continue;
  35. }
  36. String combinedKey = pages[0]+"->"+pages[1]+"->"+pages[2];
  37. Integer old = counts.get(combinedKey);
  38. if (old == null) {
  39. old = 0;
  40. }
  41. counts.put(combinedKey, old + 1);
  42. }
  43. for (Map.Entry<String,Integer> e : counts.entrySet()) {
  44. System.out.println(e.getKey() + " " + e.getValue());
  45. }
  46.  
  47. }
  48. }
Success #stdin #stdout 0.1s 380672KB
stdin
1248977297 BBBB Search
1248977302 AAAA Browse
1248977308 BBBB Search
1248977310 AAAA Browse
1248977317 BBBB Search
1248977325 AAAA Search
1248977332 AAAA Search
1248977332 BBBB Search
1248977339 BBBB Checkout
1248977348 AAAA Search
1248977352 BBBB Browse
1248977367 AAAA Search
stdout
Browse->Search->Search 1
Search->Search->Checkout 1
Browse->Browse->Search 1
Search->Checkout->Browse 1
Search->Search->Search 4