Advertisement
Martina312

Speluvanje

Feb 8th, 2020
230
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.84 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. class Zbor implements Comparable<Zbor>{
  4.     String zbor;
  5.  
  6.     public Zbor(String zbor) {
  7.         this.zbor = zbor;
  8.     }
  9.     @Override
  10.     public boolean equals(Object obj) {
  11.         Zbor pom = (Zbor) obj;
  12.         return this.zbor.equals(pom.zbor);
  13.     }
  14.     @Override
  15.     public int hashCode() {
  16.         return zbor.hashCode();
  17.     }
  18.     @Override
  19.     public String toString() {
  20.         return zbor;
  21.     }
  22.     @Override
  23.     public int compareTo(Zbor arg0) {
  24.         return zbor.compareTo(arg0.zbor);
  25.     }
  26. }
  27.  
  28.  
  29. public class Speluvanje {
  30.     public static void main(String[] args) {
  31.         Scanner in=new Scanner(System.in);
  32.  
  33.         int n=Integer.parseInt(in.nextLine());
  34.         OBHT<Zbor, Zbor> table=new OBHT<>(2*n);
  35.         for(int i=0;i<n;i++){
  36.             String word=in.nextLine();
  37.             Zbor z=new Zbor(word);
  38.             table.insert(z,z);
  39.         }
  40.  
  41.         String text=in.nextLine();
  42.         String [] parts=text.split(" ");
  43.  
  44.         int nepravilno=0;
  45.         for(int i=0;i<parts.length;i++){
  46.             if(parts[i].equals("."))
  47.                 break;
  48.             String word=parts[i];
  49.             if(!Character.isLetter(parts[i].charAt(parts[i].length()-1))) {
  50.                 word = parts[i].substring(0, parts[i].length() - 1);
  51.             }
  52.             word=word.substring(0,1).toLowerCase()+word.substring(1).toLowerCase();
  53.             int index=table.search(new Zbor(word));
  54.  
  55.             if(index==-1){
  56.                 System.out.println(word);
  57.                 nepravilno++;
  58.                 continue;
  59.             }
  60.             if(table.getValue(index).compareTo(new Zbor(word))!=0){
  61.                 System.out.println(word);
  62.                 nepravilno++;
  63.             }
  64.         }
  65.         if(nepravilno==0){
  66.             System.out.println("Bravo");
  67.         }
  68.     }
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement