C79-波兰表达式(前缀)
原题链接:28705.NoteSC++2025-10-25 12:08:06
发布于:江苏
一、前缀表达式

二、前缀表达式的计算过程



三、进制转换程序
1. 十进制转二进制
#include <bits/stdc++.h>
#include <stack>
using namespace std;
stack<int> stk;
int main(){
int n; cin >> n;
while (n){
stk.push(n%2);
n /= 2;
}
while (stk.size()){
cout<<stk.top(); //输出栈顶
stk.pop(); //弹栈
}
return 0;
}
2. 十进制转任意进制
#include <bits/stdc++.h>
#include <stack>
using namespace std;
stack<int> stk;
int main(){
int r, n;
cin >> r >> n;
while (n){
stk.push(n%r);
n /= r;
}
while (stk.size()){
if (stk.top() > 9) cout << (char)(stk.top()+55);
else cout<<stk.top();
stk.pop(); //弹栈
}
return 0;
}
作业
全部评论 1
|||||||||||||||||||||||||||||||
5天前 来自 江苏
0










有帮助,赞一个