第一题完成
This commit is contained in:
@@ -37,5 +37,6 @@ int pop(stack &s) {
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
int e = s.data[s.top];
|
int e = s.data[s.top];
|
||||||
|
s.top--;
|
||||||
return e;
|
return e;
|
||||||
}
|
}
|
||||||
|
|||||||
+17
-1
@@ -2,7 +2,23 @@
|
|||||||
#include<iostream>
|
#include<iostream>
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
int main() {
|
string getBinary(int i) {
|
||||||
|
stack s;
|
||||||
|
initStack(s);
|
||||||
|
while (i != 0) {
|
||||||
|
push(s, i % 2);
|
||||||
|
i /= 2;
|
||||||
|
}
|
||||||
|
string str = "";
|
||||||
|
while (!isEmpty(s)) {
|
||||||
|
str += pop(s) + '0';
|
||||||
|
}
|
||||||
|
return str;
|
||||||
|
}
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
int decimal;
|
||||||
|
cin >> decimal;
|
||||||
|
cout << getBinary(decimal) << endl;;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user