728x90
반응형
https://www.acmicpc.net/problem/1076
#include<stdio.h>
#include<iostream>
#include<vector>
#include<map>
#include<string>
using namespace std;
map <string, int>res = {
{"black",0},
{"brown",1},
{"red",2},
{"orange",3},
{"yellow",4},
{"green",5},
{"blue",6},
{"violet",7},
{"grey",8},
{"white",9},
};
int main(void) {
string color1, color2, color3;
cin >> color1 >> color2 >> color3; //색상 지정
long long int ans = (res[color1] * 10) + res[color2]; //미리 계산
for (int i = 0; i < res[color3]; i++) { //10의 제곱승 계산하기
ans *= 10;
}
cout << ans;// 최종결과
return 0;
}
간단한 문제지만 map stl을 이용하여 구현한 알고리즘 입니다. 정말 간편하게 구현이 되지 않나요
stl 같은것은 잘 알아두면 정말 쉽게 구현 가능합니다.
그리고 컴파일러는 c++로하면 안되고 c++11이상으로 하셔야합니다.
이런 차이가 있으니까요. 참고해주세요
728x90
반응형
'알고리즘 모음집 > New 알고리즘' 카테고리의 다른 글
1193 분수찾기 (0) | 2020.08.24 |
---|---|
1181 단어 정렬 (0) | 2020.08.24 |
프로그래머스 k번째 수 (0) | 2020.08.20 |
17142 연구소 3 (0) | 2020.08.20 |
프로그래머스 프린터 (0) | 2020.08.19 |
댓글