求逆波兰式,不知道问题出在哪,大牛们,秋梨膏!

#include <iostream>
#include<string>
#include<cstring>
using namespace std;
    int panduan(char a)
    {
        if(char a='(') return 6;
        if(char a=')') return 5;
        if(char a='*') return 4;
        if(char a='+') return 3;
        if(char a='-') return 2;
        if(char a='/') return 1;
        if(char a='#') return 0;
    }
int main()
{
    string str1;
    cin>>str1;
    int a,kuohaomar1,p,q;
    int s1mark=-1;
    int optrhead=0;
    int length_str=str1.length();
    char fuhao[length_str];
    char s1[length_str];
    str1.copy(fuhao,length_str,0);
    char optr[length_str];
    for(a=0;a<length_str;a++)
     optr[a]='#';
    for(a=0;a<length_str;a++)
    {
        if(fuhao[a]>='0'&&fuhao[a]<='9')
        {
            s1mark=+1;
            s1[s1mark]=fuhao[a];
            break;
        }
        else{
                if(panduan(fuhao[a])>panduan(optr[optrhead]))
                     {
                            optrhead=+1;
                            optr[optrhead]=fuhao[a];
                                break;
                                         }
                    if(panduan(fuhao[a]<panduan(optr[optrhead])))
                        {
                             s1mark=+1;
                            s1[s1mark]=optr[optrhead];
                            optr[optrhead]=fuhao[a];
                                break;
                             }
                    if(fuhao[a]='(')
                            {
                                  kuohaomar1=optrhead;
                                     optrhead=+1;
                                        optr[optrhead]=fuhao[a];
                                                 break;
                                                        }
                     if(fuhao[a]=')')
                            {
                                 for(p=kuohaomar1+1;p<a;p++)
                                {
                                    s1mark=+1;
                                        s1[s1mark]=optr[p];
                                }
                                     for(p=kuohaomar1;p<=a;p++)
                                            {
                                                optr[p]='0';
                                            }
                                        optrhead=optrhead-kuohaomar1;
                                         break;
                                 }
        }
    }
    for(q=optrhead;q>=1;q--)
    {
        s1mark=+1;
        s1[s1mark]=optr[q];
    }
    for(a=0;a<length_st r;a++)
        cout<<s1[a]<<" ";
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值