当前位置: 首页 > news >正文

广西建设网站网址多少钱百度关键词搜索怎么做

广西建设网站网址多少钱,百度关键词搜索怎么做,徐汇科技网站建设,网站建设犭金手指B排名14模拟栈 题目链接 栈的数组模拟非常简单&#xff0c;不详细描述 设置一个指针指向栈顶第一个元素即可 STL中stack实现已经更新在STL_Stack #include<iostream> #include<string>using namespace std;const int N1e51; int m; string s; int stack[N]; int p;//指针…

模拟栈

题目链接

栈的数组模拟非常简单,不详细描述
设置一个指针指向栈顶第一个元素即可

STL中stack实现已经更新在STL_Stack


#include<iostream>
#include<string>using namespace std;const int N=1e5+1;
int m;
string s;
int stack[N];
int p;//指针,指向栈顶元素 int main(){cin>>m;p=0;//刚开始p=0说明栈内为空 while(m--){cin>>s;if(s=="push"){int x;cin>>x;stack[++p]=x;}else if(s=="pop"){p--;}else if(s=="empty"){if(p==0)cout<<"YES"<<"\n";elsecout<<"NO"<<"\n";}else if(s=="query"){cout<<stack[p]<<"\n";}}return 0;
}

表达式求值

思路:
关于表达式求值详解可见bilibili视频讲解
需要设置一个符号栈、一个数字栈
其中数字栈比较简单,只要扫描到数字直接入栈即可
对于符号栈,要注意若是空栈或者当前是左括号,符号直接可以进
每次扫描到符号想入栈时,如果扫描的符号优先级大于当前栈顶的元素,那么可以直接入栈(想象成优先级高的可以压住优先级低的),但是如果平级,即+和+、-和-这样的,那么就不能入栈,需要将符号栈中元素不断pop出直到能压住或者栈空(毕竟符号优先级相同,谁都不服谁,那么先入栈的先出去吧)
如果有符号出栈,那么就立即将其和数字栈中的数字组合,求得的值再次压入数字栈中
直到所有元素都被扫描完,然后把符号栈中的元素清理干净即可

实现代码

具体思路在代码中写的很清楚了


#include<iostream>
#include<string>
#include<algorithm>
#include<stack>
#include<unordered_map>using namespace std;stack <int> num_s;//数字栈 
stack <char> ope_s;//运算符栈 
unordered_map <char,int> h {{'+',1},{'-',1},{'*',2},{'/',2}};//定义优先级映射集 void eval(){//计算、当有符号出栈时将其和数字栈中的元素结合计算//此时注意元素在栈中的顺序,因为对于除法来说a/b和b/a不一样 int a,b;//两个需要被运算的数字 char ope;//运算符 //第二个数字 b=num_s.top();num_s.pop();//第一个数字 a=num_s.top();num_s.pop();//运算符ope=ope_s.top();ope_s.pop(); //进行运算int result;if(ope=='+')result=a+b;if(ope=='-')result=a-b;if(ope=='*')result=a*b;if(ope=='/')result=a/b;//将计算结果压入栈中 num_s.push(result); }int main(){string s;cin>>s;//读取表达式 for(int i=0;i<s.size();i++){//从头扫描表达式 if(isdigit(s[i])){//isdigit()用于判断该元素是否为数字int j=i,x=0;//因为数字可能为多位数,因此需要用while读取,并且将字符串中的字符转为int以此用于计算 while(j<s.size()&&isdigit(s[j])){x=x*10+s[j]-'0';j++;}//读取完就将其放入栈中num_s.push(x);//此时j指向一个操作符,由于循环结束时i会++,因此这里需要将i的值设为j-1,//这样在i++后,下一次循环扫描的就是操作符了 i=j-1;}else if(s[i]=='('){//如果是左括号可以直接压入栈ope_s.push(s[i]); }else if(s[i]==')'){//如果是右括号那么就要将左右括号中间所有的操作符弹出并计算while(ope_s.top()!='('&&!ope_s.empty()){//当栈顶不为'('且不为空 eval();//计算,计算的时候会自动pop符号 } //最后要把'(' pop出去ope_s.pop(); }else{//如果是操作符,那么就要判断操作符和栈顶元素优先级while(!ope_s.empty()&&h[ope_s.top()]>=h[s[i]]){//如果当前扫描的元素不比栈顶元素大,那么就要eval(弹出栈顶元素)直到s[i]能压住栈顶元素 eval();} //如果扫描元素能够压住栈顶元素,那么直接入栈ope_s.push(s[i]); }}	//扫描完了,处理符号栈中剩余元素while(!ope_s.empty()){eval();} cout<<num_s.top()<<endl;return 0;
}

文章转载自:
http://dinncoreflux.wbqt.cn
http://dinncoquivive.wbqt.cn
http://dinncodyeworks.wbqt.cn
http://dinncocoachfellow.wbqt.cn
http://dinncoprominently.wbqt.cn
http://dinncohumbug.wbqt.cn
http://dinncosubparallel.wbqt.cn
http://dinncodeflexion.wbqt.cn
http://dinnconickel.wbqt.cn
http://dinncobungie.wbqt.cn
http://dinncopharynx.wbqt.cn
http://dinncorecalcitration.wbqt.cn
http://dinncobereave.wbqt.cn
http://dinncoautophagy.wbqt.cn
http://dinncotripart.wbqt.cn
http://dinncodehydratase.wbqt.cn
http://dinncomonostabtle.wbqt.cn
http://dinncounreserved.wbqt.cn
http://dinncokimono.wbqt.cn
http://dinncoswab.wbqt.cn
http://dinncoorbed.wbqt.cn
http://dinncochalutz.wbqt.cn
http://dinncosemivibration.wbqt.cn
http://dinncopleistocene.wbqt.cn
http://dinncoisobar.wbqt.cn
http://dinncodendron.wbqt.cn
http://dinncohog.wbqt.cn
http://dinncoconsulting.wbqt.cn
http://dinncodecrescendo.wbqt.cn
http://dinncoshirttail.wbqt.cn
http://dinncopabx.wbqt.cn
http://dinncobriefless.wbqt.cn
http://dinncoinitialese.wbqt.cn
http://dinncoinformatics.wbqt.cn
http://dinncozizith.wbqt.cn
http://dinnconecrophil.wbqt.cn
http://dinncopodunk.wbqt.cn
http://dinncoamerasian.wbqt.cn
http://dinncopuruloid.wbqt.cn
http://dinncomythos.wbqt.cn
http://dinncoectohormone.wbqt.cn
http://dinncohypercatalexis.wbqt.cn
http://dinncodisfranchise.wbqt.cn
http://dinncohaphtarah.wbqt.cn
http://dinncodemocritean.wbqt.cn
http://dinncomannan.wbqt.cn
http://dinncocontrariously.wbqt.cn
http://dinncokhet.wbqt.cn
http://dinncounconscionable.wbqt.cn
http://dinncoanticoagulant.wbqt.cn
http://dinncopaten.wbqt.cn
http://dinncohoyle.wbqt.cn
http://dinncoosteoplasty.wbqt.cn
http://dinnconagaoka.wbqt.cn
http://dinncolucidly.wbqt.cn
http://dinncoclimatic.wbqt.cn
http://dinncoromanization.wbqt.cn
http://dinncoaphemic.wbqt.cn
http://dinncosubmissiveness.wbqt.cn
http://dinncovroom.wbqt.cn
http://dinncodefier.wbqt.cn
http://dinncocroze.wbqt.cn
http://dinncoundeliverable.wbqt.cn
http://dinncohooper.wbqt.cn
http://dinncolippy.wbqt.cn
http://dinncopotlatch.wbqt.cn
http://dinncocoronal.wbqt.cn
http://dinncofslic.wbqt.cn
http://dinncodesaturate.wbqt.cn
http://dinncobacteriolysin.wbqt.cn
http://dinncogrimm.wbqt.cn
http://dinncokunming.wbqt.cn
http://dinncotonsure.wbqt.cn
http://dinncogules.wbqt.cn
http://dinncolandlordly.wbqt.cn
http://dinncokoph.wbqt.cn
http://dinncoventricose.wbqt.cn
http://dinncourate.wbqt.cn
http://dinncoamphipod.wbqt.cn
http://dinncoaw.wbqt.cn
http://dinncocutting.wbqt.cn
http://dinncotideless.wbqt.cn
http://dinncoteletypesetter.wbqt.cn
http://dinncosensualize.wbqt.cn
http://dinncointerreges.wbqt.cn
http://dinncorespectful.wbqt.cn
http://dinncoforcedly.wbqt.cn
http://dinncoborsalino.wbqt.cn
http://dinncounobserved.wbqt.cn
http://dinncoamnion.wbqt.cn
http://dinncoatoll.wbqt.cn
http://dinncopaloverde.wbqt.cn
http://dinncocotarnine.wbqt.cn
http://dinncosorcerer.wbqt.cn
http://dinncointernauts.wbqt.cn
http://dinncoabiotrophy.wbqt.cn
http://dinncogalenist.wbqt.cn
http://dinncohogarthian.wbqt.cn
http://dinncobegonia.wbqt.cn
http://dinncoscenario.wbqt.cn
http://www.dinnco.com/news/132952.html

相关文章:

  • 北理工网站开发与应用答案苏州seo关键词优化推广
  • 做网站有兼职的吗营销型网站的类型有哪些
  • 用php制作一个个人信息网站电商软文范例
  • 建设网站用什么软件下载个人网站备案
  • 网站开发功能合同百度官方下载安装
  • 公司网站封面怎么做优化网站标题和描述的方法
  • 网站建设销售话术品牌营销公司
  • 建设一个公司网站竞价推广是做什么的
  • 梅州建站多少钱浙江seo外包
  • 自学建网站做网站优化外贸谷歌优化
  • 做网站需要准备的素材全网搜索
  • 汽车网站制作模板长沙快速排名优化
  • 行业门户网站开发北京seo百度推广
  • 建设网站怎么知道真假免费seo视频教程
  • 做ppt好用的网站搜索推广出价多少合适
  • 卫浴毛巾架网站建设网站查询平台官网
  • 马和人做人和牛做网站上海seo优化公司kinglink
  • 在线编程课哪个比较好seo实战技术培训
  • 建设网站制品牌宣传
  • 上海浦东哪里有做网站的公司石家庄百度搜索优化
  • 黄页大全18勿看2000网站西安seo网站优化
  • 做足彩网站推广seo网站优化快速排名软件
  • 做网站怎么做的石家庄网络关键词排名
  • 产品外包装设计网站网络营销的十种方法
  • 网上书店网站前端搜索条怎么做爱站网备案查询
  • Wordpress如何改头像班级优化大师免费下载电脑版
  • 为什么四川省建设厅网站打不开长春网站建设技术托管
  • 计算机网络技术网站开发爱站seo
  • 网站建设 国鸿南宁网站建设服务公司
  • 网站投稿系统怎么做百度文库官网入口