Question: hexadecimal conversion, plus legal judgment.
Analysis: number theory. Convert it to decimal, convert it to the corresponding hexadecimal format, and then output it.
Base to decimal: multiply the order by base addition;
Convert decimal to base: returns the remainder of base in reverse order.
Note: When the value is 0.
# Include <iostream> # include <cstdlib> # include <cstdio> using namespace STD; char number1 [11]; int ctoi (char ch) {If (CH> = '0' & Ch <= '9') return ch-'0'; else return ch-'A' + 10 ;} char itoc (INT v) {If (v <10) return V + '0'; else return V + 'a'-10;} void dtob2 (long V, int B2) {If (v) {dtob2 (V/B2, B2); printf ("% C", itoc (V % B2) ;}} int main () {int base1, base2; while (~ Scanf ("% d % s", & base1, & base2, number1) {// int flag = 0; For (INT I = 0; number1 [I]; ++ I) if (ctoi (number1 [I])> = base1) Flag = 1; if (FLAG) {printf ("% s is an illegal base % d Number \ n", number1, base1); Continue ;}// convert it to a 10th hexadecimal value long value = 0ll; for (INT I = 0; number1 [I]; ++ I) {value * = base1; Value + = ctoi (number1 [I]);} // convert to base 2 hexadecimal number printf ("% s base % d =", number1, base1); If (value = 0ll) printf ("0 "); else dtob2 (value, base2); printf ("base % d \ n", base2);} return 0 ;}
Ultraviolet A 355-the bases are loaded