Advertisement
anhkiet2507

WeAreNoStrangersToLoveYouKnowTheRulesAndSoDoI

Oct 18th, 2022
1,278
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.85 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.text.SimpleDateFormat;
  7. import java.util.concurrent.TimeUnit;
  8. public class main {
  9.     public static String cht(String s){
  10.         String res = "";
  11.         String[] st = s.trim().split("\\s+");
  12.         for(int j = 0; j < st.length; j++){
  13.             String i = st[j];
  14.             res = res + i.substring(0, 1).toUpperCase() + i.substring(1).toLowerCase();
  15.             if(j!=st.length - 1){
  16.                 res = res + " ";
  17.             }
  18.         }
  19.         return res;
  20.     }
  21.     static class SV{
  22.         private String ma;
  23.         private String ten;
  24.         private String lop;
  25.         private String email;
  26.         private String dn;
  27.         public SV(String ma, String ten, String lop, String email){
  28.             this.ma = ma;
  29.             this.ten = cht(ten);
  30.             this.lop = lop;
  31.             this.email = email;
  32.         }
  33.         public void setDn(String dn){
  34.             this.dn = dn;
  35.         }
  36.         public String getMa(){
  37.             return ma;
  38.         }
  39.         @Override
  40.         public String toString(){
  41.             return ma + " " + ten + " " + lop;
  42.         }
  43.     }
  44.     static class DN{
  45.         private String ma;
  46.         private String ten;
  47.         private int sl;
  48.         public DN(String ma, String ten, int sl){
  49.             this.ma = ma;
  50.             this.ten = ten;
  51.             this.sl = sl;
  52.         }
  53.     }
  54.     static class TT{
  55.         private String ma;
  56.         private String dn;
  57.         public TT(String ma, String dn){
  58.             this.dn = dn;
  59.             this.ma = ma;
  60.         }
  61.         public String getMa(){
  62.             return ma;
  63.         }
  64.     }
  65.     public static void main(String[] args) throws FileNotFoundException {
  66. //        Scanner cin = new Scanner(new File("E:\\OOP\\CodeUltimate\\src\\main\\java\\com\\kietna\\codeultimate\\SINHVIEN.in"));
  67. //        Scanner cin2 = new Scanner(new File("E:\\OOP\\CodeUltimate\\src\\main\\java\\com\\kietna\\codeultimate\\DN.IN"));
  68. //        Scanner cin3 = new Scanner(new File("E:\\OOP\\CodeUltimate\\src\\main\\java\\com\\kietna\\codeultimate\\THUCTAP.IN"));
  69.         Scanner cin = new Scanner(new File("SINHVIEN.in"));
  70.         Scanner cin2 = new Scanner(new File("DN.IN"));
  71.         Scanner cin3 = new Scanner(new File("THUCTAP.IN"));
  72.         List<SV> dssv = new ArrayList<>();
  73.         List<DN> dsdn = new ArrayList<>();
  74.         List<TT> dstt = new ArrayList<>();
  75.         int numsv = Integer.parseInt(cin.nextLine());
  76.         while(numsv-->0){
  77.             String masv = cin.nextLine();
  78.             String tensv = cin.nextLine();
  79.             String lop = cin.nextLine();
  80.             String email = cin.nextLine();
  81.             SV sv = new SV(masv,tensv,lop,email);
  82.             dssv.add(sv);
  83.         }
  84.         int numdn = Integer.parseInt(cin2.nextLine());
  85.         while(numdn-->0){
  86.             String madn = cin2.nextLine();
  87.             String tendn = cin2.nextLine();
  88.             int amount = Integer.parseInt(cin2.nextLine());
  89.             DN dn = new DN(madn,tendn,amount);
  90.             dsdn.add(dn);
  91.         }
  92.         int numtt = Integer.parseInt(cin3.nextLine());
  93.         while(numtt-->0){
  94.             String all = cin3.nextLine();
  95.             String st[] = all.split("\\s+");
  96.             String matt = st[0];
  97.             String dntt = st[1];
  98.             TT tt = new TT(matt, dntt);
  99.             dstt.add(tt);
  100.         }
  101.         dstt.sort(Comparator.comparing(TT::getMa));
  102.         ArrayList<String> cnt = new ArrayList<>();
  103.         for(TT i : dstt){
  104.             int limit = 0;
  105.             String madnnhan = "";
  106.             for(DN k : dsdn){
  107.                 if(i.dn.equals(k.ma)){
  108.                     limit = k.sl;
  109.                     madnnhan = k.ma;
  110.                 }
  111.             }
  112.             for(SV j : dssv){
  113.                 if(j.ma.equals(i.ma)){
  114.                     cnt.add(madnnhan);
  115.                     int count = Collections.frequency(cnt, madnnhan);
  116.                     if(count <= limit){
  117.                         j.setDn(madnnhan);
  118.                     }
  119.                 }
  120.             }
  121.         }
  122.         int req = Integer.parseInt(cin3.nextLine());
  123.         while(req-->0){
  124.             String madnreq = cin3.nextLine();
  125.             String tendnreq = "";
  126.             for(DN i : dsdn){
  127.                 if(i.ma.equals(madnreq)){
  128.                     tendnreq = i.ten;
  129.                 }
  130.             }
  131.             System.out.println("DANH SACH THUC TAP TAI " + tendnreq + ":");
  132.             List<SV>dssvtt = new ArrayList<>();
  133.             for(SV i : dssv){
  134.                 if(i.dn.equals(madnreq)){
  135.                     dssvtt.add(i);
  136.                 }
  137.             }
  138.             dssvtt.sort(Comparator.comparing(SV::getMa));
  139.             for(SV j : dssvtt){
  140.                 System.out.println(j);
  141.             }
  142.         }
  143.        
  144.     }
  145. }
  146.  
  147.  
  148.  
  149.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement