Advertisement
roronoa

city population

Jul 17th, 2019
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.67 KB | None | 0 0
  1. import java.util.*;
  2. import java.io.*;
  3. import java.math.*;
  4.  
  5. class Solution {
  6.  
  7.     public static void main(String args[]) {
  8.         Scanner in = new Scanner(System.in);
  9.         int n = in.nextInt();
  10.         Map<String, Integer> map = new HashMap<>();
  11.         for (int i = 0; i < n; i++)
  12.         {
  13.             String city = in.next();
  14.             int population = in.nextInt();
  15.             map.put(city, population);
  16.         }
  17.         in.nextLine();
  18.         String search = in.nextLine();
  19.         int sum = 0;
  20.         for(String x : map.keySet())
  21.             if(x.indexOf(search) != -1)
  22.                 sum += map.get(x);
  23.  
  24.         System.out.println(sum);
  25.     }
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement