Advertisement
Rayk

shi ta plesna

Feb 28th, 2018
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.21 KB | None | 0 0
  1. import java.io.BufferedReader;
  2. import java.io.IOException;
  3. import java.io.InputStreamReader;
  4. import java.util.LinkedHashMap;
  5. import java.util.Map;
  6.  
  7. public class Veronika {
  8.     public static void main(String[] args) throws IOException {
  9.         BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
  10.  
  11.         String line = reader.readLine();
  12.  
  13.         LinkedHashMap<Character, Integer> symbolCount = countSymbols(line);
  14.  
  15.         int max = -1;
  16.         char maxCh = 'a';
  17.         for (Map.Entry<Character, Integer> entry : symbolCount.entrySet()) {
  18.             if (entry.getValue() > max) {
  19.                 max = entry.getValue();
  20.                 maxCh = entry.getKey();
  21.             }
  22.         }
  23.  
  24.         if (max > 1){
  25.             //TODO CHANGE THE WORD
  26.         }
  27.     }
  28.  
  29.     private static LinkedHashMap<Character, Integer> countSymbols(String line) {
  30.         LinkedHashMap<Character, Integer> counter = new LinkedHashMap<>();
  31.  
  32.         for (char ch : line.toCharArray()) {
  33.             if (counter.containsKey(ch)) {
  34.                 counter.put(ch, counter.get(ch) + 1);
  35.             } else {
  36.                 counter.put(ch, 1);
  37.             }
  38.         }
  39.  
  40.         return counter;
  41.     }
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement