Andziev

Статичко рутирање

Nov 22nd, 2016
1,231
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.27 KB | None | 0 0
  1. import java.util.*;
  2.  
  3. public class RoutingHashJava {
  4.    
  5.     public static void main (String [] args) {
  6.         Scanner sc = new Scanner (System.in);
  7.         HashMap <String,String> map = new HashMap <> ();
  8.         int N = Integer.parseInt(sc.nextLine());
  9.        
  10.         for(int i=0; i<N; i++)
  11.             map.put(sc.nextLine(),sc.nextLine());
  12.        
  13.         N = Integer.parseInt(sc.nextLine());
  14.         for(int i=0; i<N; i++) {
  15.            
  16.             String tester = sc.nextLine();  
  17.             String [] parts = sc.nextLine().split("\\.");
  18.             boolean itHas = false;
  19.            
  20.             if(!map.containsKey(tester))
  21.                 System.out.println("ne postoi");
  22.            
  23.             else {
  24.                 String [] temps = map.get(tester).split("\\,");
  25.                
  26.                 for(int j=0; j<temps.length; j++) {
  27.                     String [] address = temps[j].split("\\.");                
  28.                     if(address[0].equals(parts[0]) && address[1].equals(parts[1]) && address[2].equals(parts[2]))
  29.                         itHas = true;
  30.                 }
  31.                 if(itHas)
  32.                     System.out.println("postoi");
  33.                 else
  34.                     System.out.println("ne postoi");
  35.             }
  36.         }
  37.     }
  38. }
Advertisement
Add Comment
Please, Sign In to add comment