Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.ArrayDeque;
- import java.util.Scanner;
- import java.util.regex.Matcher;
- import java.util.regex.Pattern;
- public class Internships {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- int countTask = Integer.parseInt(scanner.nextLine());
- int countPerson = Integer.parseInt(scanner.nextLine());
- String regex = "^[A-Z][a-z]+ [A-Z][a-z]+$";
- Pattern pattern = Pattern.compile(regex);
- ArrayDeque<String> tasks = new ArrayDeque<>();
- ArrayDeque<String> names = new ArrayDeque<>();
- for (int i = 0; i < countTask; i++) {
- String current = scanner.nextLine().trim();
- tasks.push(current);
- }
- for (int i = 0; i < countPerson; i++) {
- String current = scanner.nextLine();
- Matcher matcher = pattern.matcher(current);
- if (matcher.find()) {
- names.addLast(current);
- }
- }
- // todo MOST IMPORTANT PART-------------
- while (tasks.size() > 0 && names.size() > 1) {
- String problem = tasks.peek();
- String[] currentTask = problem.split("");
- int sumTask = 0;
- for (int i = 0; i < currentTask.length; i++) {
- sumTask += currentTask[i].charAt(0);
- }
- String name = names.pop();
- String[] currentName = name.split("");
- int sumName = 0;
- for (int i = 0; i < currentName.length; i++) {
- sumName += currentName[i].charAt(0);
- }
- if (sumName > sumTask) {
- tasks.pop();
- names.addLast(name);
- System.out.println(name + " solved " + problem + ".");
- } else {
- tasks.pop();
- tasks.addLast(problem);
- System.out.println(name + " failed " + problem + ".");
- }
- }
- if (names.size() == 1) {
- System.out.println(names.peek() + " gets the job!");
- } else {
- // for (int i = 0; i < names.size(); i++) {
- // if (i == names.size() - 1) {
- // System.out.println(names.pop());
- // } else {
- // System.out.print(names.pop() + ", ");
- // }
- // i--;
- // }
- System.out.println(String.join(", ", names));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement