第一题完成

This commit is contained in:
2024-10-23 21:27:48 +08:00
parent 935832dbe8
commit ff38d0b314
2 changed files with 18 additions and 1 deletions
+1
View File
@@ -37,5 +37,6 @@ int pop(stack &s) {
return NULL;
}
int e = s.data[s.top];
s.top--;
return e;
}
+17 -1
View File
@@ -2,7 +2,23 @@
#include<iostream>
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;
}