令人讨厌的字符串处理,写完人都不好了。不想写解析了,以后有时间再来补。
#include<cstdio>
#include<cstring>
#include<stack>
using namespace std;
bool isnum(char c)
{
if(c>='0'&&c<='9') return true;
else return false;
}
int priority[128];
void initial()
{
priority['('] = 0;
priority['+'] = 1;
priority['-'] = 1;
priority['*'] = 2;
priority['/'] = 2;
}
int main()
{
initial();
char exp[21];
char postfix[41];
int p = 0;
stack<char> s;
scanf("%s",exp);
int len = strlen(exp);
for(int i=0; i<len; ){
if(exp[i]=='+'||exp[i]=='-'){
if(i==0||!isnum(exp[i-1])&&exp[i-1]!=')'){
if(exp[i]=='-') postfix[p++] = '-';
i++;
while(i<len&&isnum(exp[i])||exp[i]=='.'){
postfix[