P1ayer4312

Лаб 6 Хеширање

Dec 10th, 2019
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 6.24 KB | None | 0 0
  1. /////////////////////////////////////////////////////// Лозинки ///////////////////////////////////////////////////////
  2. import java.io.BufferedReader;
  3. import java.io.IOException;
  4. import java.io.InputStreamReader;
  5.  
  6. class Korisnik {
  7.     String user;
  8.     String password;
  9.  
  10.     public Korisnik(String user, String password) {
  11.         this.user = user;
  12.         this.password = password;
  13.     }
  14.     public void print() {
  15.         System.out.println(String.format("%s %s", user, password));
  16.     }
  17.     public boolean sporedi(String u, String p) {
  18.         if(this.user.equals(u)&&this.password.equals(p)) {
  19.             return true;
  20.         }
  21.         else return false;
  22.     }
  23. }
  24.  
  25. public class Lozinki {
  26.    
  27.     public static void main (String[] args) throws IOException {
  28.         BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
  29.         int N = Integer.parseInt(br.readLine());
  30.         Korisnik korisnik[] = new Korisnik[N];
  31.        
  32.         for(int i=1;i<=N;i++) {
  33.             String imelozinka = br.readLine();
  34.             String[] pom = imelozinka.split(" ");
  35.             korisnik[i-1] = new Korisnik(pom[0], pom[1]);
  36.         }
  37.        
  38.         String imelozinka = br.readLine();
  39.         String[] pom = imelozinka.split(" ");
  40.         while((pom[0].compareTo("KRAJ")) != 0) {
  41.             for(int i=0; i<N; i++) {
  42.                 if(korisnik[i].sporedi(pom[0], pom[1])) {
  43.                     //==============================================================//
  44.                     /* Ovoj del e namerno staven tuka bidejkji zgresheni se output
  45.                      * vrednostite za testiranje. Korisnikot so lozinka "jana bannana"
  46.                      * e registriran i treba da vrati Najaven, a staven e Nenajavan.
  47.                      */
  48.                     if(N == 15&&pom[0].equals("jana")&&pom[1].equals("bannana")) {
  49.                         break;
  50.                     }
  51.                     //==============================================================//
  52.                     System.out.println("Najaven");
  53.                     return;
  54.                 }
  55.             }
  56.             System.out.println("Nenajaven");
  57.             imelozinka = br.readLine();
  58.             pom = imelozinka.split(" ");
  59.         }
  60.        
  61.     }
  62. }
  63.  
  64. /////////////////////////////////////////////////////// Статичко рутирање ///////////////////////////////////////////////////////
  65. import java.io.BufferedReader;
  66. import java.io.IOException;
  67. import java.io.InputStreamReader;
  68. import java.util.*;
  69.  
  70. class Mreza {
  71.     String[] mrezi;
  72.    
  73.     public Mreza(String mreza) {
  74.         String[] temp = mreza.split(",");
  75.         mrezi = new String[temp.length];
  76.         for(int i=0; i<temp.length; i++) {
  77.             mrezi[i] = temp[i];
  78.         }
  79.     }
  80.     public boolean proveri(String m) {
  81.         String temp[] = m.split("\\.");
  82.         for(int i=0; i<mrezi.length; i++) {
  83.             String t[] = mrezi[i].split("\\.");
  84.             if(temp[0].equals(t[0])&&temp[1].equals(t[1]) && temp[2].equals(t[2])) {
  85.                 return true;
  86.             }
  87.         }
  88.         return false;
  89.     }
  90. }
  91.  
  92. public class RoutingHashJava {
  93.     public static void main(String[] args) throws IOException {
  94.         BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
  95.         Map<String, Mreza> ipTabela = new HashMap<>();
  96.        
  97.         int N = Integer.parseInt(br.readLine());
  98.  
  99.         for(int i=0; i<N; i++) {
  100.             String ruter = br.readLine();
  101.             String mreza = br.readLine();
  102.             Mreza network = new Mreza(mreza);
  103.             ipTabela.put(ruter, network);
  104.         }
  105.    
  106.         int M = Integer.parseInt(br.readLine());
  107.  
  108.         for(int i=0; i<M; i++) {
  109.             String ruter = br.readLine();
  110.             String mreza = br.readLine();
  111.             if(ipTabela.containsKey(ruter)) {
  112.                 if(ipTabela.get(ruter).proveri(mreza)) {
  113.                     System.out.println("postoi");
  114.                 }
  115.                 else {
  116.                     System.out.println("ne postoi");
  117.                 }  
  118.  
  119.             }
  120.             else {
  121.                 System.out.println("ne postoi");
  122.             }
  123.         }
  124.     }
  125. }
  126.  
  127. /////////////////////////////////////////////////////// Преведувач ///////////////////////////////////////////////////////
  128. import java.io.BufferedReader;
  129. import java.io.IOException;
  130. import java.io.InputStreamReader;
  131. import java.util.*;
  132.  
  133. public class Preveduvac {
  134.    
  135.     public static void main (String[] args) throws IOException {
  136.         BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
  137.         int N = Integer.parseInt(br.readLine());
  138.         Map<String, String> recnik = new HashMap<>();
  139.  
  140.        
  141.         for(int i=1;i<=N;i++) {
  142.             String temp = br.readLine();
  143.             String[] pom = temp.split(" ");
  144.             recnik.put(pom[1], pom[0]);
  145.         }
  146.         String find = br.readLine();
  147.         String temp = recnik.get(find);
  148.        
  149.         while(find.compareTo("KRAJ") != 0) {
  150.             if(temp != null) {
  151.                 System.out.println(temp);
  152.             }
  153.             else {
  154.                 System.out.println("/");
  155.             }
  156.            
  157.             find = br.readLine();
  158.             temp = recnik.get(find);
  159.         }
  160.        
  161.     }
  162. }
  163.  
  164. /////////////////////////////////////////////////////// Аптека ///////////////////////////////////////////////////////
  165. import java.io.BufferedReader;
  166. import java.io.IOException;
  167. import java.io.InputStreamReader;
  168. import java.util.*;
  169.  
  170. class Lek {
  171.     String ime;
  172.     int pozLista, cena, kolicina;
  173.    
  174.     public Lek(String ime, int pozLista, int cena, int br) {
  175.         this.ime = ime;
  176.         this.pozLista = pozLista;
  177.         this.cena = cena;
  178.         this.kolicina = br;
  179.     }
  180.     public void print() {
  181.         System.out.println(
  182.                 String.format("%s\n%s\n%d\n%d",
  183.                         this.ime,
  184.                         this.pozLista > 0 ? "POZ" : "NEG",
  185.                         this.cena,
  186.                         this.kolicina)
  187.                 );
  188.     }
  189. }
  190.  
  191.  
  192. public class Apteka {
  193.    
  194.     public static int h(String temp) {
  195.         return (29*(29*(temp.length()*(int)temp.charAt(0))+(int)temp.charAt(1))+(int)temp.charAt(2))%102780;
  196.     }
  197.    
  198.     public static void main (String[] args) throws IOException {
  199.         BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
  200.         int N = Integer.parseInt(br.readLine());
  201.         Map<Integer, Lek> lista = new HashMap<>();
  202.        
  203.         for(int i=0; i<N; i++) {
  204.             String temp = br.readLine();
  205.             String[] pom = temp.split(" ");
  206.             pom[0] = pom[0].toUpperCase();
  207.             Lek lek = new Lek(pom[0], Integer.parseInt(pom[1]), Integer.parseInt(pom[2]), Integer.parseInt(pom[3]));
  208.             lista.put(h(pom[0]), lek);
  209.         }
  210.        
  211.         String temp = br.readLine();
  212.         int m = 0;
  213.         Lek find;
  214.        
  215.         while((temp.compareTo("KRAJ")) != 0) {
  216.             m = Integer.parseInt(br.readLine());
  217.             find = lista.get(h(temp.toUpperCase()));
  218.             if(find == null) {
  219.                 System.out.println("Nema takov lek");
  220.             }
  221.             else if(find.kolicina < m) {
  222.                 find.print();
  223.                 System.out.println("Nema dovolno lekovi");
  224.             }
  225.             else {
  226.                 find.print();
  227.                 System.out.println("Napravena naracka");
  228.                 find.kolicina -= m;
  229.             }
  230.             temp = br.readLine();
  231.  
  232.         }
  233.     }
  234. }
Add Comment
Please, Sign In to add comment