被欸嘿诅咒的代码,虽然AC,但是谁用谁就会惨死(楼上上是出音味来,楼上上上是猎头别吃)

被欸嘿诅咒的代码,虽然AC,但是谁用谁就会惨死(楼上上是出音味来,楼上上上是猎头别吃)

程序员王斌爱玩原神 · 发布于 2025-02-28 · 浏览 434 回复 0

include <bits/stdc++.h>

using namespace std; int check(char c){

int a=0;
if(c=='+'||c=='-'){
	a=1;
}
if(c=='*'||c=='/'){
	a=2;
}
if(c=='^'){
	a=3;
}
return a;

} stacknum; stackop; void deal() {

int a, b;
b=num.top();
num.pop();
a=num.top();
num.pop();
char p=op.top();
op.pop();
if(p=='+'){
	num.push(a+b);
}
if(p=='-'){
	num.push(a-b);
}
if(p=='*'){
	num.push(a*b);
}
if(p=='/'){
	num.push(a/b);
}
if(p=='^'){
	int d=pow(a,b);
	num.push(d);
}

}

void ceal(){

string s;
getline(cin,s);
for (int i=0;i<s.size();i++){
	int d=0;
	if(s[i]>='0'&&s[i]<='9'){
		while(s[i]>='0'&&s[i]<='9'){
			int a=s[i]-'0';
			d=d*10+a;
			i++;
		}
		i--;
		num.push(d);
	}
	else if(s[i]=='('||s[i]==')'){
		if(s[i]=='('){
			op.push(s[i]);
		}
		else if(s[i]==')'){
			while(op.top()!='('){
				deal();
			}
			op.pop();
		}
	}
	else{
		while(op.size()>0&&check(op.top())>=check(s[i])){
			deal();
		}
		op.push(s[i]);
	}
}
while(!op.empty()){
	deal();
}
cout<<num.top();

} int main(){

ceal();
return 0;

}

全部回复 共 0 条

还没有人回复。往下写第一条。

发表回复