백준 1550 c++

magicdrill·2024년 4월 4일
0

백준 문제풀이

목록 보기
256/654

백준 1550 c++

#include <iostream>

using namespace std;

int main(void)
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);

	string s;
	int i;
	int dec = 0;
	int j = 1;

	cin >> s;
	for (i = s.length() - 1; i >= 0; i--)
	{
		if (s[i] == 'A')
		{
			dec += 10 * j;
		}
		else if (s[i] == 'B')
		{
			dec += 11 * j;
		}
		else if (s[i] == 'C')
		{
			dec += 12 * j;
		}
		else if (s[i] == 'D')
		{
			dec += 13 * j;
		}
		else if (s[i] == 'E')
		{
			dec += 14 * j;
		}
		else if (s[i] == 'F')
		{
			dec += 15 * j;
		}
		else
		{
			dec += (s[i] - '0') * j;
		}
		j = j * 16;
	}
	cout << dec << "\n";

	return 0;
}

0개의 댓글