YJ/C++
[백준/BOJ/C++] 1076번 저항
Team DAON
2021. 10. 21. 16:44
[문제]
전자 제품에는 저항이 들어간다. 저항은 색 3개를 이용해서 그 저항이 몇 옴인지 나타낸다. 처음 색 2개는 저항의 값이고, 마지막 색은 곱해야 하는 값이다. 저항의 값은 다음 표를 이용해서 구한다.
색값곱
색 | 값 | 곱 |
black | 0 | 1 |
brown | 1 | 10 |
red | 2 | 100 |
orange | 3 | 1,000 |
yellow | 4 | 10,000 |
green | 5 | 100,000 |
blue | 6 | 1,000,000 |
violet | 7 | 10,000,000 |
grey | 8 | 100,000,000 |
white | 9 | 1,000,000,000 |
예를 들어, 저항의 색이 yellow, violet, red였다면 저항의 값은 4,700이 된다.
[입력]
첫째 줄에 첫 번째 색, 둘째 줄에 두 번째 색, 셋째 줄에 세 번째 색이 주어진다. 위의 표에 있는 색만 입력으로 주어진다.
[출력]
입력으로 주어진 저항의 저항값을 계산하여 첫째 줄에 출력한다.
[Source Code]
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
using namespace std;
long long result = 0;
void change(string color){
result *= 10;
if(color == "black") result += 0;
else if(color == "brown") result += 1;
else if(color == "red") result += 2;
else if(color == "orange") result += 3;
else if(color == "yellow") result += 4;
else if(color == "green") result += 5;
else if(color == "blue") result += 6;
else if(color == "violet") result += 7;
else if(color == "grey") result += 8;
else if(color == "white") result += 9;
}
void mul(string color){
if(color == "black") result *= 1;
else if(color == "brown") result *= 10;
else if(color == "red") result *= 100;
else if(color == "orange") result *= 1000;
else if(color == "yellow") result *= 10000;
else if(color == "green") result *= 100000;
else if(color == "blue") result *= 1000000;
else if(color == "violet") result *= 10000000 ;
else if(color == "grey") result *= 100000000;
else if(color == "white") result *= 1000000000;
}
int main() {
string first, second, third, output;
cin >> first >> second >> third;
change(first);
change(second);
mul(third);
cout << result;
}
[결과 화면]