반응형
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 32 33 34 35 36 37 38 39 40 41 42 43 44 | #include <iostream> #include <string.h> #include <cmath> using namespace std; int main() { char word[7]; int ans = 0; cin >> word; for (int i = 0; i < strlen(word); i++) { if (word[i] == 'A') { ans+=pow(16,strlen(word)-i-1)*10; } else if (word[i] == 'B') { ans += pow(16, strlen(word) - i-1) * 11; } else if (word[i] == 'C') { ans += pow(16, strlen(word) - i-1) * 12; } else if (word[i] == 'D') { ans += pow(16, strlen(word) - i-1) * 13; } else if (word[i] == 'E') { ans += pow(16, strlen(word) - i-1) * 14; } else if (word[i] == 'F') { ans += pow(16, strlen(word) - i-1) * 15; } else { ans += pow(16, strlen(word) - i-1)*(word[i] - '0'); } } cout << ans; } | cs |
'Algorithm' 카테고리의 다른 글
C++(씨쁠쁠)(cplusplus)-백준(baekjoon)(BaekJoon)코딩 2920번:음계 답 (0) | 2016.11.24 |
---|---|
(C++) - 백준(BOJ) 1934번 : 최소공배수 (0) | 2016.11.24 |
C++(씨쁠쁠)(cplusplus)-백준(baekjoon)(BaekJoon)코딩 3047번:ABC 답 (0) | 2016.11.23 |
C++(씨쁠쁠)(cplusplus)-백준(baekjoon)(BaekJoon)코딩 10214번:Baseball 답 (0) | 2016.11.22 |
(C++) - 백준(BOJ) 2476 : 주사위 게임 답 (0) | 2016.11.22 |