Crazy Binary Conversion II |
Time limit:1000 MS |
Memory limit:32768 K |
Total submit:309(196 users) |
Total accepted:219(193 users) |
Rating: |
Special Judge: No |
|
Description |
The binary conversion is a crazy question, you need to convert an integer into a 32-bit binary form. |
Input |
There are several sets of test data, for each group of data input a positive integer number,number no more than 32-bit signed integer maximum value, input to the end of the file. |
Output |
Outputs a corresponding 32-bit binary string for each set of data and wraps it. |
Sample Input |
1 2 |
Sample Output |
00000000000000000000000000000001 00000000000000000000000000000010 |
Solve this problem with a new stack and queue knowledge.
#include <iostream> #include <stack>using namespace Std;int main () {int N;while (cin>>n) {Stack<int >ls;while (n!=0) {Ls.push (n%2); n/=2;} for (int i=0;i<32-ls.size (); i++) Cout<<0;while (!ls.empty ()) {cout<<ls.top (); Ls.pop ();} Cout<<endl;} return 0;}
Crazy Binary Conversion II