가장 많이 사용된 단어 찾기 여러개일경우 -> ? 대소문자 구분없음
Mississipi
?
zZa
Z
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 | import java.util.*; import java.util.Map.Entry; public class Main { public static void main(String[] args) { //97~122 아스키 a-z //65~90 대문자 A-Z Scanner sc = new Scanner(System.in); String str = sc.nextLine().trim().toUpperCase(); char topChar = 0; int topCount = 0; Map<Character , Integer> map = new HashMap<>(); for(int i=0; i<str.length() ;i++) { map.put(str.charAt(i), map.get(str.charAt(i)) == null ? 1 : map.get(str.charAt(i))+1); } Iterator<Map.Entry<Character, Integer>> iter =map.entrySet().iterator(); while(iter.hasNext()) { Entry<Character , Integer> entry = iter.next(); if(topCount < entry.getValue()) { topCount = entry.getValue(); topChar = entry.getKey(); }else if(topCount == entry.getValue()) { topChar = '?'; } } System.out.println(topChar); } } |
'오락기 > codeWar' 카테고리의 다른 글
백준 5622 다이얼 (0) | 2018.05.25 |
---|---|
백준 2908 상수 (0) | 2018.05.25 |
2675 백준 문자열반복 (0) | 2018.05.11 |
백준 10809 알파벳찾기 (0) | 2018.05.11 |
백준 11654 (0) | 2018.05.11 |