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

  • <center id="usuqs"></center>
  • 
    
  • C++邏輯表達(dá)式運(yùn)算

    C++邏輯表達(dá)式運(yùn)算
    邏輯表達(dá)式運(yùn)算
    由大寫英文字母和符號(hào)~、 *、+、()組成邏輯表達(dá)式,其中三個(gè)符號(hào)分別表示邏輯非、與、或運(yùn)算,英文字母表示變量,變量有兩種可能的取值,FALSE(0)或TRUE(1),、*、+、括號(hào)()可改變表達(dá)式的運(yùn)算次序,且可以嵌套.編一個(gè)程序計(jì)算邏輯表達(dá)式的值.
    【輸入格式】
    輸入為若干行
    第一行字符串s(1
    其他人氣:912 ℃時(shí)間:2020-04-16 17:54:29
    優(yōu)質(zhì)解答
    #include
    using namespace std;
    #define MAXSIZE 100
    #define CHARNUM 26
    //定義棧結(jié)構(gòu)體
    typedef struct _stack
    {
    char data[MAXSIZE];
    int top;
    } stack;
    //將輸入邏輯表達(dá)式字符串轉(zhuǎn)換為逆波蘭式的字符串
    void translate(const char *p,char *pout)
    {
    stack op;
    op.top=-1;
    int i=0;
    while (*p!='\0')
    {
    switch (*p)
    {
    case '(':
    op.data[++op.top]=*p;
    *p++;
    break;
    case ')':
    while (op.data[op.top]!='(')
    {
    pout[i++]=op.data[op.top];
    op.top--;
    }
    op.top--;
    *p++;
    break;
    case ':
    op.data[++op.top]=*p;
    *p++;
    break;
    case '*':
    case '+':
    while ((op.top!=-1)&&(op.data[op.top]!='('))
    {
    pout[i++]=op.data[op.top];
    op.top--;
    }
    op.data[++op.top]=*p;
    *p++;
    break;
    case ' ':
    break;
    default:
    pout[i++]=*p;
    *p++;
    }
    }
    while (op.top!=-1)
    {
    pout[i++]=op.data[op.top];
    op.top--;
    }
    pout[i]='\0';
    }
    //逆波蘭式的求解
    bool calculator(const char* str)
    {
    stack st;
    st.top=-1;
    char ch0,ch1,c;
    while (*str!='\0')
    {
    switch (*str)
    {
    case '0':
    case '1':
    st.data[++st.top]=*str;
    break;
    case ':
    ch0=st.data[st.top--];
    c=!(ch0-'0')+'0';
    st.data[++st.top]=c;
    break;
    case '+':
    ch0=st.data[st.top--];
    ch1=st.data[st.top--];
    c=((ch0-'0')||(ch1-'0'))+'0';
    st.data[++st.top]=c;
    break;
    case '*':
    ch0=st.data[st.top--];
    ch1=st.data[st.top--];
    c=((ch0-'0')&&(ch1-'1'))+'0';
    st.data[++st.top]=c;
    break;
    default:
    break;
    }
    *str++;
    }
    return st.data[st.top]-'0';
    }
    int main()
    {
    char str[MAXSIZE]={0};
    int chartab[CHARNUM]={0};
    fstream infile;
    fstream outfile;
    int sum;
    //打開輸入和輸出文件
    infile.open("stackc.in",fstream::in);
    outfile.open("stackc.out",fstream::out);
    //獲取第一行字符串
    infile.getline(str,MAXSIZE);
    //獲取第二行整數(shù)
    sum=infile.get()-'0';
    infile.get();
    //得到各個(gè)變量的值
    for (int i=0;i
    我來(lái)回答
    類似推薦
    請(qǐng)使用1024x768 IE6.0或更高版本瀏覽器瀏覽本站點(diǎn),以保證最佳閱讀效果。本頁(yè)提供作業(yè)小助手,一起搜作業(yè)以及作業(yè)好幫手最新版!
    版權(quán)所有 CopyRight © 2012-2024 作業(yè)小助手 All Rights Reserved. 手機(jī)版