精品偷拍一区二区三区,亚洲精品永久 码,亚洲综合日韩精品欧美国产,亚洲国产日韩a在线亚洲

  • <center id="usuqs"></center>
  • 
    
  • 求用以下類似程序編一個(gè)可以計(jì)算括號的計(jì)算器

    求用以下類似程序編一個(gè)可以計(jì)算括號的計(jì)算器
    #include
    #define smax 10
    #define emax 255
    int power(int x,int y)
    {
    int t,s=1;
    for (t=0; t=48 && ex[i]=rinput && rtop!=0)
    {
    //計(jì)算
    //數(shù)字出戰(zhàn)
    top=top-1;
    x=s[top];
    top=top-1;
    y=s[top];
    s[top]=calc(o,x,y);
    top=top+1;
    //讀出下一個(gè)棧頂符號
    otop=otop-1;
    o=op[otop];
    if (o=='+')
    rtop=0;
    else
    if (o=='-') rtop=1;
    }
    //原先的放回
    op[otop]=o;
    otop=otop+1;
    //新的符號入棧
    op[otop]=ex[i];
    otop=otop+1;
    }
    }
    i=i+1;
    }
    while (otop!=0)
    {
    //數(shù)字出戰(zhàn)
    top=top-1;
    x=s[top];
    top=top-1;
    y=s[top];
    //符號出棧
    otop=otop-1;
    o=op[otop];
    s[top]=calc(o,x,y);
    top=top+1;
    }
    ans= s[0];
    //輸出結(jié)果
    printf("%s=%d\n",ex,ans);
    }
    其他人氣:381 ℃時(shí)間:2020-06-02 06:32:30
    優(yōu)質(zhì)解答
    將()當(dāng)成op處理即可可以具體編寫一下么?謝謝/*上面同原程序*/void main(){ int s[smax]; char op[smax]; int top=0; int otop=0; int i,num,x,y; int rtop,rinput; char o; char ex[emax]; scanf("%s", ex); i=0; num=0; s[0]=0; top=1; op[0]='+'; otop=1;while (1) {if (ex[i] >=48 && ex[i]<58) { while (ex[i] >=48 && ex[i]<58)num=num*10+ex[i++]-48; s[top++]=num; num=0; } else if (ex[i]==0) break; else if (ex[i]=='(') op[otop++]=ex[i++];else if (ex[i]==')'){o=op[--otop];while (o!='(') {x=s[--top];y=s[--top];s[top++]=calc(o,x,y); o=op[--otop]; }i++;} else { rinput=rank(ex[i]);o=op[--otop];rtop=rank(o);while (rtop>=rinput && rtop!=0 && o!='('){x=s[--top]; y=s[--top]; s[top++]=calc(o,x,y); o=op[--otop]; rtop=rank(o); }op[otop++]=o;op[otop++]=ex[i++];} } while (otop!=0) {x=s[--top];y=s[--top];o=op[--otop];s[top++]=calc(o,x,y); } printf("%s=%d\n",ex,s[0]); getch();}
    我來回答
    類似推薦
    請使用1024x768 IE6.0或更高版本瀏覽器瀏覽本站點(diǎn),以保證最佳閱讀效果。本頁提供作業(yè)小助手,一起搜作業(yè)以及作業(yè)好幫手最新版!
    版權(quán)所有 CopyRight © 2012-2024 作業(yè)小助手 All Rights Reserved. 手機(jī)版