Advertisement
anhkiet2507

SussyBaka

Oct 18th, 2022
1,454
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.50 KB | None | 0 0
  1. package com.kietna.codeultimate;
  2.  
  3. import java.text.*;
  4. import java.util.*;
  5. import java.io.*;
  6. import java.time.*;
  7. import java.util.concurrent.TimeUnit;
  8. public class main {
  9.     static class NV{
  10.         private String ten;
  11.         private String cv;
  12.         private String hs;
  13.         private String maso;
  14.         public NV(String ma, String ten){
  15.             this.cv = ma.substring(0, 2);
  16.             this.hs = ma.substring(2, 4);
  17.             this.maso = ma.substring(4, 7);
  18.             this.ten = ten;
  19.         }
  20.  
  21.         public void setCv(String cv) {
  22.             this.cv = cv;
  23.         }
  24.        
  25.        
  26.  
  27.         public String getHs() {
  28.             return hs;
  29.         }
  30.  
  31.         public String getMaso() {
  32.             return maso;
  33.         }
  34.        
  35.         @Override
  36.         public String toString(){
  37.             return ten + " " + cv + " " + maso + " " + hs;
  38.         }
  39.        
  40.     }
  41.     public static void main(String[] args) throws FileNotFoundException, Exception {
  42.         Scanner cin = new Scanner(System.in);
  43. //        Scanner cin = new Scanner(new File("E:\\OOP\\CodeUltimate\\src\\main\\java\\com\\kietna\\codeultimate\\input.txt"));
  44.         int t = Integer.parseInt(cin.nextLine());
  45.         int num = t;
  46.         List<NV> dsnv = new ArrayList<>();
  47.         while(t-->0){
  48.             String ma = cin.next();
  49.             String ten = cin.nextLine();
  50.             NV nv = new NV(ma,ten);
  51.             dsnv.add(nv);
  52.         }
  53.         int req = Integer.parseInt(cin.nextLine());
  54.         while(req-->0){
  55.             String request = cin.nextLine();
  56.             int limit = 0;
  57.             if(request.equals("GD")){
  58.                 limit = 1;
  59.             }else if(request.equals("TP")){
  60.                 limit = 3;
  61.             }else if(request.equals("PP")){
  62.                 limit = 3;
  63.             }else if(request.equals("NV")){
  64.                 limit = num;
  65.             }
  66.             List<NV> dsin = new ArrayList<>();
  67.             int count = 0;
  68.             for(NV i : dsnv){
  69.                 if(i.cv.equals(request) && count < limit){
  70.                     dsin.add(i);
  71.                     count++;
  72.                 }else if(i.cv.equals(request) && count >= limit){
  73.                     i.setCv("NV");
  74.                 }
  75.             }
  76.             dsin.sort(Comparator.comparing(NV::getHs).reversed().thenComparing(NV::getMaso));
  77.            
  78.             for(NV i : dsin){
  79.                 System.out.println(i);
  80.             }
  81.             System.out.println();
  82.         }
  83.     }
  84. }
  85.  
  86.  
  87.  
  88.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement