Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Submission of Jedi Meditation by ivanrachev97gmailcom April 13, 2018, 6:53 a.m.
- Java 9
- View status
- View raw source
- Resubmit
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- import java.util.Scanner;
- import java.util.regex.Matcher;
- import java.util.regex.Pattern;
- public class JediMeditation
- {
- public static void main(String[] args)
- {
- Scanner input = new Scanner(System.in);
- int n = input.nextInt();
- input.nextLine();
- String unordered = input.nextLine().trim();
- Matcher masters = Pattern.compile("M\\d+").matcher(unordered);
- Matcher knights = Pattern.compile("K\\d+").matcher(unordered);
- Matcher padawans = Pattern.compile("P\\d+").matcher(unordered);
- StringBuilder ordered = new StringBuilder();
- while (masters.find())
- ordered.append(masters.group()).append(" ");
- while (knights.find())
- ordered.append(knights.group()).append(" ");
- while (padawans.find())
- ordered.append(padawans.group()).append(" ");
- System.out.println(ordered.toString());
- }
- }
- Telerik Academy | Powered by DMOJ
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement