Advertisement
Martina312

Untitled

Feb 9th, 2020
181
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.01 KB | None | 0 0
  1. import java.util.Objects;
  2. import java.util.Scanner;
  3.  
  4. class Mail implements Comparable<Mail>{
  5.     private String title;
  6.     private String date;
  7.     private String time;
  8.     private String state;
  9.     private int num;
  10.  
  11.     public Mail(String title, String date, String time, String state) {
  12.         this.title = title;
  13.         this.date = date;
  14.         this.time = time;
  15.         this.state = state;
  16.         num=0;
  17.     }
  18.  
  19.     public String getState() {
  20.         return state;
  21.     }
  22.  
  23.     @Override
  24.     public boolean equals(Object o) {
  25.         if (this == o) return true;
  26.         if (o == null || getClass() != o.getClass()) return false;
  27.         Mail mail = (Mail) o;
  28.         return Objects.equals(date, mail.date) &&
  29.                 Objects.equals(time, mail.time) && Objects.equals(title, mail.title);
  30.     }
  31.  
  32.     @Override
  33.     public int hashCode() {
  34.         return Objects.hash(title, time,date);
  35.     }
  36.  
  37.     @Override
  38.     public String toString() {
  39.         return title+" "+date+" "+time+" "+state;
  40.     }
  41.  
  42.     @Override
  43.     public int compareTo(Mail o) {
  44.         return time.compareTo(o.time);
  45.     }
  46.  
  47.     public int getNum() {
  48.         return num;
  49.     }
  50.  
  51.     public void changeState(String command){
  52.         if(command.equals("delete")){
  53.             state="TRASH";
  54.         }else if(command.equals("unread")){
  55.             if(state.equals("READ") || state.equals("UNREAD")) {
  56.                 state = "UNREAD";
  57.             }
  58.         }else{
  59.             if(state.equals("READ") || state.equals("UNREAD")) {
  60.                 state = "READ";
  61.             }
  62.         }
  63.         num++;
  64.     }
  65. }
  66. public class Mails {
  67.     public static void main(String[] args) {
  68.         Scanner in=new Scanner(System.in);
  69.         int n=Integer.parseInt(in.nextLine());
  70.  
  71.         CBHT<Mail, Mail> table=new CBHT<>(2*n);
  72.         for(int i=0;i<n;i++){
  73.             String line=in.nextLine();
  74.             String [] parts=line.split(" ");
  75.  
  76.             Mail mail=new Mail(parts[0],parts[1],parts[2],parts[3]);
  77.             SLLNode<MapEntry<Mail,Mail>> temp=table.search(mail);
  78.             if(temp==null){
  79.                 table.insert(mail,mail);
  80.             }
  81.         }
  82.  
  83.  
  84.         int obidi=Integer.parseInt(in.nextLine());
  85.         for(int i=0;i<n;i++){
  86.             String line=in.nextLine();
  87.             String [] delovi=line.split("_");
  88.             String [] parts=delovi[1].split(" ");
  89.             Mail m=new Mail(parts[0],parts[1],parts[2],"");
  90.  
  91.             SLLNode<MapEntry<Mail,Mail>> temp=table.search(m);
  92.             if(temp!=null){
  93.                 temp.element.value.changeState(delovi[0]);
  94.             }
  95.         }
  96.  
  97.  
  98.         String line=in.nextLine();
  99.         String [] parts=line.split(" ");
  100.         Mail m=new Mail(parts[0],parts[1],parts[2],"");
  101.         SLLNode<MapEntry<Mail,Mail>> temp=table.search(m);
  102.         if(temp==null){
  103.             System.out.println("Mejlot ne postoi");
  104.         }else{
  105.             System.out.println(temp.element.value.getState()+" "+temp.element.value.getNum());
  106.         }
  107.     }
  108. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement