작성
·
157
0
왜죠?
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
String input = in.next();
System.out.println(new Main().solution(input));
}
private String solution(String input) {
Map<Character, Integer> map = new HashMap<>();
Set<Character> keySet = new LinkedHashSet<>();
for (int i = 0; i < input.length(); i++) {
keySet.add(input.charAt(i));
map.put(input.charAt(i), map.getOrDefault(input.charAt(i), 0) + 1);
}
StringBuilder sb = new StringBuilder();
keySet.forEach(character -> {
if (map.get(character) > 1) {
sb.append(character).append(map.get(character));
} else {
sb.append(character);
}
});
return String.valueOf(sb);
}
}
답변 1
1