알고리즘

[알고리즘] 백준 11816 - 8진수, 10진수, 16진수 (C++)

blueberrysoda 2024. 11. 17. 23:20

[문제 링크] : https://www.acmicpc.net/problem/11816

#include <iostream>
using namespace std;

int main(){
    string N;
    cin >> N;

    if(N.length() > 1){
        if(N.substr(0, 2) == "0x"){
            cout << stoi(N, nullptr, 16) << "\n";
        }
        else if(N.substr(0, 1) == "0"){
            cout << stoi(N, nullptr, 8) << "\n";
        }
        else{
            cout << N << "\n";
        }
    }
    return 0;
}