Zookeeper Data structure experiment stack 1: hexadecimal conversion Time Limit: 1000 ms memory limit: 65536 k any questions? Click Here ^_^ Enter a decimal integer, convert it to the corresponding R (2 <= r <= 9) hexadecimal number, and output. Enter the number of decimal places to be converted in the first line;
Enter R in the second line. Output The number of R in hexadecimal format. Sample Input
12798
Sample output
2377
Prompt source sample program
The background data is too watery. It is reasonable to consider the case of zero, but it is true that you do not judge zero.
# Include <stdio. h> # include <string. h> # include <stdlib. h >#include <iostream >#include <stack> using namespace STD; int main () {int n, m; stack <int> q; while (~ Scanf ("% d", & N, & M) {If (n = 0) printf ("0"); else while (n> 0) {int z = n % m; q. push (z); // stack N/= m;} while (! Q. empty () {printf ("% d", Q. top (); // output stack Q. pop (); // cancel} printf ("\ n");} return 0 ;}
Data structure experiment stack 1: hexadecimal conversion (stack Application)