알고리즘 풀이/프로그래머스
[프로그래머스][JAVA] 광고 삽입 (string 문자 치환)
배게
2021. 9. 11. 11:13
728x90
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 | import java.util.*; class Solution { public int solution(String s) { Map<String, Integer> map = new HashMap<>(); map.put("zero", 0); map.put("one", 1); map.put("two", 2); map.put("three", 3); map.put("four", 4); map.put("five", 5); map.put("six", 6); map.put("seven", 7); map.put("eight", 8); map.put("nine", 9); System.out.println(s); for(Map.Entry<String,Integer> entry : map.entrySet()){ // System.out.println(entry.getValue()); // System.out.println(entry.getKey()); s = s.replace(entry.getKey(),String.valueOf(entry.getValue())); } // System.out.println(s); int answer = Integer.parseInt(s); return answer; } } | cs |