日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 人文社科 > 生活经验 >内容正文

生活经验

pat 表达式转换

發(fā)布時(shí)間:2023/11/27 生活经验 30 豆豆
生活随笔 收集整理的這篇文章主要介紹了 pat 表达式转换 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

好多細(xì)節(jié)多找點(diǎn)數(shù)據(jù)輸入輸出看看自己哪里有不足就行了吧

#include<bits/stdc++.h>
using namespace std;
string str;
int flag=1;
int f=1;
bool op(int i,char c)
{if(str[i-1]>'9'||str[i-1]<'0'&&(str[i-1]!=')'))return 0;if(c=='+'||c=='-'||c=='*'||c=='/')return true;return false;
}
bool out(int i,char c)
{if(c>='0'&&c<='9')return 1;if(c=='.')return 1;if(c=='-'){if(i==0)return 1;else if(str[i-1]>='0'&&str[i-1]<='9'||str[i-1]==')')return 0;return 1;}return 0;
}
map<char,int > m;
void solve(int l,int r)
{stack<char> s;for(int i=l;i<=r;i++){if(out(i,str[i])){if(flag==1||f){flag=0;f=1;cout<<str[i];}else{f=1;cout<<' '<<str[i];}}else if(op(i,str[i])){f=0;if(!s.empty()){while(m[str[i]]<=m[s.top()]){cout<<' '<<s.top();f=0;s.pop();if(s.empty())break;}}s.push(str[i]);}else if(str[i]=='('){stack<char> q; int j=i+1;q.push('(');while(!q.empty()){if(str[j]==')')q.pop();else if(str[j]=='(')q.push('(');j++;}solve(i+1,j-2);i=j-1;}}while(!s.empty()){f=0;cout<<' '<<s.top();s.pop();}
}
int main()
{m['+']=1;m['-']=1;m['*']=2;m['/']=2;cin>>str;solve(0,str.length());
} 


總結(jié)

以上是生活随笔為你收集整理的pat 表达式转换的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。