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