Advertisement
Guest User

Untitled

a guest
Jul 17th, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.21 KB | None | 0 0
  1.  
  2.  
  3. Submission of Jedi Meditation by ivanrachev97gmailcom April 13, 2018, 6:53 a.m.
  4. Java 9
  5.  
  6. View status
  7. View raw source
  8. Resubmit
  9.  
  10.  
  11. 1
  12. 2
  13. 3
  14. 4
  15. 5
  16. 6
  17. 7
  18. 8
  19. 9
  20. 10
  21. 11
  22. 12
  23. 13
  24. 14
  25. 15
  26. 16
  27. 17
  28. 18
  29. 19
  30. 20
  31. 21
  32. 22
  33. 23
  34. 24
  35. 25
  36. 26
  37. 27
  38. 28
  39. 29
  40. 30
  41. 31
  42. import java.util.Scanner;
  43. import java.util.regex.Matcher;
  44. import java.util.regex.Pattern;
  45.  
  46. public class JediMeditation
  47. {
  48.     public static void main(String[] args)
  49.     {
  50.         Scanner input = new Scanner(System.in);
  51.  
  52.         int n = input.nextInt();
  53.  
  54.         input.nextLine();
  55.         String unordered = input.nextLine().trim();
  56.  
  57.         Matcher masters = Pattern.compile("M\\d+").matcher(unordered);
  58.         Matcher knights = Pattern.compile("K\\d+").matcher(unordered);
  59.         Matcher padawans = Pattern.compile("P\\d+").matcher(unordered);
  60.  
  61.         StringBuilder ordered = new StringBuilder();
  62.  
  63.         while (masters.find())
  64.             ordered.append(masters.group()).append(" ");
  65.         while (knights.find())
  66.             ordered.append(knights.group()).append(" ");
  67.         while (padawans.find())
  68.             ordered.append(padawans.group()).append(" ");
  69.  
  70.         System.out.println(ordered.toString());
  71.     }
  72. }
  73. Telerik Academy | Powered by DMOJ
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement