Untitled

 avatar
unknown
plain_text
3 years ago
2.6 kB
8
Indexable
package com.company;

import java.util.*;

class Staff implements Comparable<Staff> {
    private String name;
    private String position;
    private String salary_coefficient;
    private String staff_ID;

    public Staff(String name, String position, String salary_coefficient, String staff_ID) {
        this.name = name;
        this.position = position;
        this.staff_ID = staff_ID;
        this.salary_coefficient = salary_coefficient;
        correct_position();
    }

    private void correct_position() {
        System.out.println(Integer.parseInt(staff_ID));
        if (position.equals("GD") && Integer.parseInt(staff_ID) > 1)
            this.position = "NV";
        if (position.equals("TP") || position.equals("PP")  && Integer.parseInt(staff_ID) > 3)
            this.position = "NV";
    }

    public boolean find_name_by_key(String key) {
        return  (name.toLowerCase().contains(key));
    }

    @Override
    public int compareTo(Staff staff) {
        int cof_cmp = staff.salary_coefficient.compareTo(this.salary_coefficient);
        if (cof_cmp == 0)
            return this.staff_ID.compareTo(staff.staff_ID);
        else
            return cof_cmp;
    }

    @Override
    public String toString() {
        return name + " " + position + " " + staff_ID + " " + salary_coefficient;
    }
}

public class Main {


    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int No_staff = sc.nextInt();
        sc.nextLine();
        ArrayList<Staff> staffs = new ArrayList<>();
        for (int i = 0; i < No_staff; i++) {
            StringTokenizer info = new StringTokenizer(sc.nextLine(), " ");
            String ID = info.nextToken();
            String name = "";
            while (true) {
                name += info.nextToken();
                if (info.hasMoreTokens()) {
                    name += " ";
                } else break;
            }
            String position = ID.substring(0, 2);
            String salary_coefficient = ID.substring(2, 4);
            String staff_ID = ID.substring(4);
            staffs.add(new Staff(name, position, salary_coefficient, staff_ID));
        }
        Collections.sort(staffs);
        int q = sc.nextInt();
        while (q-- > 0) {
            String key = sc.next().toLowerCase();
            for (Staff staff : staffs) {
                if (staff.find_name_by_key(key))
                    System.out.println(staff);
            }
            System.out.println();
        }
    }
}
Editor is loading...