Data structure experiment stack 1: hexadecimal conversion (stack Application)

Source: Internet
Author: User
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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.