Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.HashMap;
- import java.util.Map;
- import java.util.Map.Entry;
- import java.util.Scanner;
- public class _03_LargestSequenceOfEqualStrings {
- public static void main(String[] args) {
- Scanner sc = new Scanner(System.in);
- String[] allWords = sc.nextLine().split(" ");
- Map<String, Integer> wordCounter = new HashMap<String, Integer>();
- for (String word : allWords) {
- Integer count = wordCounter.get(word);
- if(count == null){
- count = 0;
- }
- wordCounter.put(word, count + 1);
- }
- Entry<String,Integer> maxEntry = null;
- for(Entry<String,Integer> entry : wordCounter.entrySet()) {
- if (maxEntry == null || entry.getValue() > maxEntry.getValue()) {
- maxEntry = entry;
- }
- }
- for (int i = 0; i < maxEntry.getValue(); i++) {
- System.out.printf("%s ", maxEntry.getKey());
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment