Advertisement
Guest User

Untitled

a guest
May 25th, 2016
497
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.88 KB | None | 0 0
  1. import java.util.HashMap;
  2. import java.util.Scanner;
  3. import java.util.regex.Matcher;
  4. import java.util.regex.Pattern;
  5.  
  6. public class c5 {
  7.     public static void main(String[] args) {
  8.         Scanner sc = new Scanner(System.in);
  9.         String input = "";
  10.         Pattern pat = Pattern.compile("(.+)-(.+)");
  11.         HashMap<String,String > map = new HashMap<>();
  12.         while(!(input = sc.nextLine()).equals("search")){
  13.             Matcher matcher = pat.matcher(input);
  14.             if(matcher.find()) {
  15.                 map.put(matcher.group(1), matcher.group(2));
  16.             }
  17.         }
  18.         while(!(input= sc.nextLine()).equals("stop")){
  19.             if(map.containsKey(input)){
  20.                 System.out.format("%s -> %s\n",input,map.get(input));
  21.             }else{
  22.                 System.out.format("Contact %s does not exist.\n",input);
  23.             }
  24.         }
  25.     }
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement