Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.kietna.codeultimate;
- import java.text.*;
- import java.util.*;
- import java.io.*;
- import java.time.*;
- import java.util.concurrent.TimeUnit;
- public class main {
- static class NV{
- private String ten;
- private String cv;
- private String hs;
- private String maso;
- public NV(String ma, String ten){
- this.cv = ma.substring(0, 2);
- this.hs = ma.substring(2, 4);
- this.maso = ma.substring(4, 7);
- this.ten = ten;
- }
- public void setCv(String cv) {
- this.cv = cv;
- }
- public String getHs() {
- return hs;
- }
- public String getMaso() {
- return maso;
- }
- @Override
- public String toString(){
- return ten + " " + cv + " " + maso + " " + hs;
- }
- }
- public static void main(String[] args) throws FileNotFoundException, Exception {
- Scanner cin = new Scanner(System.in);
- // Scanner cin = new Scanner(new File("E:\\OOP\\CodeUltimate\\src\\main\\java\\com\\kietna\\codeultimate\\input.txt"));
- int t = Integer.parseInt(cin.nextLine());
- int num = t;
- List<NV> dsnv = new ArrayList<>();
- while(t-->0){
- String ma = cin.next();
- String ten = cin.nextLine();
- NV nv = new NV(ma,ten);
- dsnv.add(nv);
- }
- int req = Integer.parseInt(cin.nextLine());
- while(req-->0){
- String request = cin.nextLine();
- int limit = 0;
- if(request.equals("GD")){
- limit = 1;
- }else if(request.equals("TP")){
- limit = 3;
- }else if(request.equals("PP")){
- limit = 3;
- }else if(request.equals("NV")){
- limit = num;
- }
- List<NV> dsin = new ArrayList<>();
- int count = 0;
- for(NV i : dsnv){
- if(i.cv.equals(request) && count < limit){
- dsin.add(i);
- count++;
- }else if(i.cv.equals(request) && count >= limit){
- i.setCv("NV");
- }
- }
- dsin.sort(Comparator.comparing(NV::getHs).reversed().thenComparing(NV::getMaso));
- for(NV i : dsin){
- System.out.println(i);
- }
- System.out.println();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement