백준 1076

hong030·2023년 2월 4일
0
  • solved.ac 기준 브론즈 2단계 문제


풀이)
시간 단축을 위해 hashmap을 활용한다.

import java.util.HashMap;

...

HashMap<String, Integer>map = new HashMap();
map.put("first", 1);
map.put("second", 2);

map.get("first");

내 코드)

import java.io.*;
import java.util.HashMap;		

public class Main {
	public static void main(String[]args) throws IOException {
		BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
		String st1 = bf.readLine();
		String st2 = bf.readLine();
		String st3 = bf.readLine();
		
		HashMap<String, String> colors = new HashMap();
		colors.put("black", "0");
		colors.put("brown", "1");
		colors.put("red", "2");
		colors.put("orange", "3");
		colors.put("yellow", "4");
		colors.put("green", "5");
		colors.put("blue", "6");
		colors.put("violet", "7");
		colors.put("grey", "8");
		colors.put("white", "9");
		
		Long result = Long.parseLong(colors.get(st1)+colors.get(st2));
		result *= (long) Math.pow(10.0, Double.parseDouble(colors.get(st3)));
		
		System.out.println(result);
		
	}
}

profile
자바 주력, 프론트 공부 중인 초보 개발자. / https://github.com/hongjaewonP

0개의 댓글