๋ฐฑ์ค ํ์ผ ์ ๋ฆฌ ๋ฌธ์ . ํ์ฅ์ ๋ช ์์ผ๋ก ์ถ๋ ฅํ๋ ๋ฌธ์ ๋ผ treemap์ ์ฌ์ฉํด์ key๋ก ์ ๋ ฌ.
import java.io.*;
import java.util.*;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer(br.readLine());
int N = Integer.parseInt(st.nextToken()); // ํ์ผ ๊ฐ์
// ํ์ผ ํ์ฅ์ ๋ณ๋ก ์นด์ดํธ
Map<String, Integer> extensionToFreq = new TreeMap<>();
// ํ์ผ ์ ์ฅ
for (int i = 0; i < N; i++) {
String s = br.readLine();
String[] sArr = s.split("\\.");
extensionToFreq.put(sArr[sArr.length -1], extensionToFreq.getOrDefault(sArr[sArr.length -1], 0) + 1);
}
// ๊ฒฐ๊ณผ ์ถ๋ ฅ
StringBuilder sb = new StringBuilder();
for (Map.Entry<String, Integer> e : extensionToFreq.entrySet()) {
sb.append(e.getKey()).append(" ").append(e.getValue()).append("\n");
}
System.out.print(sb);
}
}
'์ฝ๋ฉํ ์คํธ > TIL' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[LC150] ๋ฆฌํธ์ฝ๋ Top Interview 150 ์์ (0) | 2025.03.11 |
---|---|
[99ํด๋ฝ] 5์ฃผ ์ฝํ ์คํฐ๋ ํ๊ธฐ (0) | 2025.02.27 |
[99ํด๋ฝ] 20์ผ์ฐจ ๋ฌธ์ : ํ์ ์ด๋ฐฅ (0) | 2025.02.15 |
[99ํด๋ฝ] 19์ผ์ฐจ ๋ฌธ์ : ์ ๋๊ฐ ํ (0) | 2025.02.13 |
[99ํด๋ฝ] 18์ผ์ฐจ ๋ฌธ์ : ํฌ๋ฆฌ์ค๋ง์ค ์ ๋ฌผ (0) | 2025.02.12 |
๋๊ธ