티스토리 뷰
더보기
#include <iostream>
using namespace std;
int main() {
string arr;
cin >> arr;
int alen=arr.length()-1;
int total = 0;
int c = 1;
while (alen >= 0) {
int index;
if (arr[alen] == 'A')index = 10;
else if (arr[alen] == 'B')index = 11;
else if (arr[alen] == 'C')index = 12;
else if (arr[alen] == 'D')index = 13;
else if (arr[alen] == 'E')index = 14;
else if (arr[alen] == 'F')index = 15;
else index = arr[alen] - '0';
total = total + c * index;
c = c * 16;
alen--;
}
cout << total;
}
16진수를 10진수로 표현한다 A~F들은 10~15로 바꿔주고
10진수에서 자릿수가 변하면 10씩 곱해지듯
16을 곱해준다
'PS' 카테고리의 다른 글
| 2609 최대공약수와 최소공배수 (0) | 2021.01.09 |
|---|---|
| 1920 수 찾기 (0) | 2021.01.09 |
| 1181 단어 정렬 (0) | 2021.01.09 |
| 1018 체스판 다시 칠하기 (0) | 2021.01.08 |
| 10757 큰수 A+B (0) | 2021.01.08 |
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
링크
TAG
- 상범빌딩
- 11657
- 1738
- tea time
- 소셜네트워킹어플리케이션
- C++
- 타임머신
- 백준
- 6539
- 1004
- 후위 표기식
- 6018
- 1918
- 중위 표기식 후위 표기식으로 변환
- 어린왕자 C++
- 스택
- 7511
- 골목길C++
- 골목길
- 벨만-포드
- 벨만포드
| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 1 | 2 | 3 | ||||
| 4 | 5 | 6 | 7 | 8 | 9 | 10 |
| 11 | 12 | 13 | 14 | 15 | 16 | 17 |
| 18 | 19 | 20 | 21 | 22 | 23 | 24 |
| 25 | 26 | 27 | 28 | 29 | 30 | 31 |
글 보관함
