#include<bits/stdc++.h> using namespace std; int char_to_num(char ch){ if(ch >= '0' && ch <= '9') return ch - '0'; else return ch - 'A' + 10; } char num_to_char(int num){ if(num >= 0 && num <= 9) return (char)( '0' + num -0); else return (char)('A' + num - 10); } long source_to_decimal(string temp, int source){ long decimal_num = 0; for(int i = 0; i < temp.size(); i ++){ decimal_num = (decimal_num * source) + char_to_num(temp[i]); } return decimal_num; } int decimal_to_object(string temp, long decimal_num, int object){ int i = 0; while(decimal_num){ temp[i] = num_to_char(decimal_num % object); decimal_num = decimal_num / object; i ++; } temp[i] = '\0'; return i; } void output(string temp, int l){ for(int i = 1; i <= l; i ++ ) cout << temp[i]; cout << endl; } int main(){ int source; int object; int l; long decimal_num; string temp; cin >> temp >> source >> object; decimal_num = source_to_decimal(temp, source); l = decimal_to_object(temp, decimal_num, object); output(temp, l); return 0; }
标签:ch,temp,19,decimal,object,source,num,打卡 From: https://www.cnblogs.com/kongxiangzeng/p/17334101.html