
Lv.1
签名:清理黑历史
在 后缀表达式+后缀表达式求值思路(c++教学) 中回复
//后缀表达式求值
#include<iostream>
#include<cstdio>
#include<stack>
using namespace std;
stack <double> s;//栈
double popfront(){
double a=s.top();
s.pop();
return a;
}
int main(){
string x;
while(cin>>x){
if('0'<=x[0]&&x[0]<='9'){
int num=stod(x);
s.push(num);
continue;
}
double a=popfront();
double b=popfront();
if(x[0]=='+'){
s.push(b+a);
}
if(x[0]=='-'){
s.push(b-a);
}
if(x[0]=='*'){
s.push(b*a);
}
if(x[0]=='/'){
s.push(b/a);
}
}
printf("%.1f",popfront());
return 0;
}2023-04-20T21:39:43 点赞:0
在 中缀转后缀思路(c++教学) 中回复
//中转后缀表达式
#include<iostream>
#include<cstdio>
#include<stack>
using namespace std;
stack <char> s;//栈
char popfront(){
char a=s.top();
s.pop();
return a;
}
int pri(char a){
switch(a){
case '(':
case ')':return 0;
case '+':
case '-':return 1;
case '*':
case '/':return 2;
}
return 0;
}
int main(){
string x;
cin>>x;
for(int i=0;i<x.size();i++){
if('0'<=x[i]&&x[i]<='9'){
int num=0;
while(1){
num*=10;
num+=x[i]-'0';
if((i+1>=x.size())||('0'>x[i+1]||x[i+1]>'9')){
break;
}
i++;
}
cout<<num<<" ";
continue;
}
//后面就是符号处理
if(x[i]=='('||s.empty()||(!s.empty() && pri(s.top())<pri(x[i]))){//无脑压入条件:左括号,栈为空,栈顶符号优先级小于当前符号
s.push(x[i]);
}else if(x[i]==')'){
while(s.top()!='(')
cout<<popfront()<<" ";
s.pop();
}else{
while(s.size()&&pri(s.top())>=pri(x[i]))
cout<<popfront()<<" ";
s.push(x[i]);
}
}
while(!s.empty()){
cout<<popfront()<<" ";
}
return 0;
}2023-04-21T13:35:23 点赞:0
在 冒泡排序(c++教学) 中回复
#include<iostream>
using namespace std;
int main(){
int a[1000],n;
cin>>n;
for(int i=0;i<n;i++)
cin>>a[i];
for(int i=0;i<n-1;i++){
for(int j=0;j<n-i-1;j++){
if(a[j]>a[j+1])swap(a[j],a[j+1]);
}
}
for(int i=0;i<n;i++)
cout<<a[i]<<" ";
cout<<endl;
return 0;
}2023-05-02T21:48:26 点赞:0
在 插入、选择排序(c++教学) 中回复
#include<iostream>
using namespace std;
int a[1000],n;
void print(){
for(int i=0;i<n;i++)
cout<<a[i]<<" ";
cout<<endl;
}
void bubble(){//冒泡
for(int i=0;i<n-1;i++){
for(int j=0;j<n-i-1;j++){
if(a[j]>a[j+1])swap(a[j],a[j+1]);
}
}
}
void select(){//选择
for(int i=0;i<n-1;i++){
int max=a[i],maxindex=i;
for(int j=n-1;j>i+1;j--){
if(max>a[j]){
max=a[j];
maxindex=j;
}
}
swap(a[i],a[maxindex]);
}
}
void insert(){//插入
for(int i=1;i<n;i++){
for(int j=i;j>0;j--){
if(a[j-1]>a[j])swap(a[j-1],a[j]);
}
}
}
int main(){
cin>>n;
for(int i=0;i<n;i++)
cin>>a[i];
// bubble();
select();
// insert();
print();
return 0;
}2023-05-03T11:56:33 点赞:0
在 后缀表达式+后缀表达式求值思路(c++教学) 中回复
//后缀表达式求值
#include<iostream>
#include<cstdio>
#include<stack>
using namespace std;
stack <double> s;//栈
double popfront(){
double a=s.top();
s.pop();
return a;
}
int main(){
string x;
while(cin>>x){
if('0'<=x[0]&&x[0]<='9'){
int num=stod(x);
s.push(num);
continue;
}
double a=popfront();
double b=popfront();
if(x[0]=='+'){
s.push(b+a);
}
if(x[0]=='-'){
s.push(b-a);
}
if(x[0]=='*'){
s.push(b*a);
}
if(x[0]=='/'){
s.push(b/a);
}
}
printf("%.1f",popfront());
return 0;
}2023-05-03T12:31:36 点赞:0
在 【教程】教你在自己的nemo作品里面使用自制排行榜(非官方私云排行榜) 中回复
猫站需要的就是这种类型的,这种教程对于猫站的影响是深刻的,就好比鲁迅对于我国文化的影响一样
2023-05-14T10:28:07 点赞:3