题解 | #进制转换#

进制转换

https://www.nowcoder.com/practice/8f3df50d2b9043208c5eed283d1d4da6

#include <iostream>
#include <string>
using namespace std;
int main() 
{
    string str;
    int i(2);
    int _temp(0);
    int dnum(0);
    while(cin >> str)
    {
        while(i < str.size())
        {
            switch(str[i])
            {
                case('A'):
                    _temp = 10;
                    break;
                case('B'):
                    _temp = 11;
                    break;
                case('C'):
                    _temp = 12;
                    break;
                case('D'):
                    _temp = 13;
                    break;
                case('E'):
                    _temp = 14;
                    break;
                case('F'):
                    _temp = 15;
                    break;
                case('\n'):
                    _temp = 0;
                    break;
                default:
                    _temp = str[i] - '0';
                    break;
            }
            dnum = dnum * 16 + _temp;
            i++;
        }
    }
    cout<<dnum<<endl;
    return 0;
}

全部评论

相关推荐

评论
1
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务