AHA Tech oj--Magical Conversion

Source: Internet
Author: User

Magical conversion of the binary
Time limit:1000 MS Memory limit:32768 K
Total submit:248(users) Total accepted:175(147 users) Rating: Special Judge: No
Description

XUXU data structure to test, so he is very hard to read, one day he looked ah look, suddenly see a conversion of the topic, said to be a decimal number into a binary number, he counted ah calculate, and then the problem solved ...

But he was very fond of thinking, how would he like to be able to convert this decimal number into a K-binary number? Ask for help, help!!!!.

Input

There are several sets of test data, for each group of data input two number n and K, N (32-bit integer) represents a decimal number, K represents the required conversion of K-ary.

(2<= k<=16).

Output

Outputs the converted number of outputs for each test instance, with one row for each output. If R is greater than 10, then the corresponding number rules refer to 16 binary (for example, 10 is indicated by a, 11 is represented by B, etc.).

Sample Input
7 223 12-4 3
Sample Output
1111b-11
Source
Freshman Practice Competition (2013.11.16)
Author

[Email protected]

This time with the stack to do, the results are good simple and simple!

#include <iostream> #include <stack>using namespace Std;int main () {int N,k;while (cin>>n>>k) { int Flag=0;stack<int>ls;if (n<0) {flag=1;n=-n;} while (n!=0) {Ls.push (n%k); n/=k;} if (flag) cout<< "-"; while (!ls.empty ()) {if (Ls.top () >9) {Cout<<char (Ls.top () -10+ ' A '); Ls.pop ();} Else{cout<<ls.top (); Ls.pop ();}} Cout<<endl;} return 0;}


AHA Tech oj--Magical Conversion

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.