알고리즘/BOJ

백준 1550번 16진수

꾸준함. 2018. 12. 1. 00:05

문제 링크입니다: https://www.acmicpc.net/problem/1550


간단한 진법 변환 문제였습니다.


#include <iostream>

#include <string>

using namespace std;

 

int main(void)

{

        ios_base::sync_with_stdio(0);

        cin.tie(0);

        string s;

        cin >> s;

 

        long long result = 0;

        long long temp = 1;

        for (int i = s.length() - 1; i >= 0; i--)

        {

                 if (s[i] >= '0' && s[i] <= '9')

                         result += (s[i] - '0')*temp;

                 else

                 {

                         switch (s[i])

                         {

                         case 'A':

                                 result += 10 * temp;

                                 break;

                         case 'B':

                                 result += 11 * temp;

                                 break;

                         case 'C':

                                 result += 12 * temp;

                                 break;

                         case 'D':

                                 result += 13 * temp;

                                 break;

                         case 'E':

                                 result += 14 * temp;

                                 break;

                         case 'F':

                                 result += 15 * temp;

                                 break;

                         }

                 }

                 temp *= 16;

        }

        cout << result << "\n";

        return 0;

}


개발환경:Visual Studio 2017


지적, 조언, 질문 환영입니다! 댓글 남겨주세요~

반응형

'알고리즘 > BOJ' 카테고리의 다른 글

백준 15633번 Fan Death  (0) 2018.12.04
백준 3047번 ABC  (0) 2018.12.01
백준 1212번 8진수 2진수  (0) 2018.12.01
백준 2153번 소수 단어  (0) 2018.11.27
백준 11286번 절댓값 힙  (0) 2018.11.24