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) {
  11. String[] aTest = new String[5]; //10 roles
  12. String[] bTest = new String[50]; // 50k strings
  13. Random test = new Random(System.currentTimeMillis());
  14. int nameLength = 20;
  15. int textSize = 50;
  16.  
  17. for (int i = 0; i < aTest.length; i++) {
  18. aTest[i] = generateString(test, "ABCDEFGHIJKLMNOPQRSTUVWXYZ ", nameLength);
  19. }
  20.  
  21. for (int i = 0; i < bTest.length; i++) {
  22. Random rand = new Random();
  23. int x = rand.nextInt(aTest.length);
  24. bTest[i] = aTest[x] + ": " + generateString(test, "ABCDEFGHIJKLMNOPQRSTUVWXYZ!@#$%&*()_+", textSize);
  25. }
  26.  
  27. long before = System.currentTimeMillis();
  28. System.out.print(printTextPerRole(aTest, bTest));
  29. System.out.println((System.currentTimeMillis() - before) + "ms.");// 8 sec(!)
  30.  
  31. }
  32.  
  33. public static String generateString(Random rng, String characters, int length) {
  34. char[] text = new char[length];
  35. for (int i = 0; i < length; i++) {
  36. text[i] = characters.charAt(rng.nextInt(characters.length()));
  37. }
  38. return new String(text);
  39. }
  40.  
  41. static private String printTextPerRole(String[] roles, String[] textLines) {
  42. StringBuilder output = new StringBuilder("");
  43. for (String role : roles) {
  44. output.append(role + ":\n");
  45. for (int i = 0; i < textLines.length; i++) {
  46. if (textLines[i].startsWith(role)) {
  47. output.append(i + 1 + ") ");
  48. output.append(textLines[i].substring(role.length() + 2));
  49. output.append("\n");
  50.  
  51. }
  52. }
  53. output.append("\n");
  54. }
  55. return output.toString();
  56. }
  57. }
Success #stdin #stdout 0.04s 320704KB
stdin
Standard input is empty
stdout
UFTBTKXETINTLJKRQMUO:
3) Q+R()JJ%@VV*SL(M$ZGI*@S*MYXICI_MLW+V&_(SM)!AOMUTPH
21) U@)CEAG&YDS_ODS+QZFR#DMC(#!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