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

学校网站建设目的外包公司什么意思

学校网站建设目的,外包公司什么意思,企业网站建设优势,网站联盟的基本流程这个题用的STL-栈来做 题目来源:洛谷 相关知识 [NOIP2013 普及组] 表达式求值 题目背景 NOIP2013 普及组 T2 题目描述 给定一个只包含加法和乘法的算术表达式,请你编程计算表达式的值。 输入格式 一行,为需要你计算的表达式&#xff…

这个题用的STL-栈来做
题目来源:洛谷
相关知识
在这里插入图片描述

[NOIP2013 普及组] 表达式求值

题目背景

NOIP2013 普及组 T2

题目描述

给定一个只包含加法和乘法的算术表达式,请你编程计算表达式的值。

输入格式

一行,为需要你计算的表达式,表达式中只包含数字、加法运算符 + 和乘法运算符 *,且没有括号,所有参与运算的数字均为 0 0 0 2 31 − 1 2^{31}-1 2311 之间的整数。

输入数据保证这一行只有 0123456789+* 12 12 12 种字符。

输出格式

一个整数,表示这个表达式的值。

注意:当答案长度多于 4 4 4 位时,请只输出最后 $ 4$ 位,前导 $ 0$ 不输出。

样例 #1

样例输入 #1

1+1*3+4

样例输出 #1

8

样例 #2

样例输入 #2

1+1234567890*1

样例输出 #2

7891

样例 #3

样例输入 #3

1+1000000003*1

样例输出 #3

4

提示

对于 30 % 30\% 30% 的数据, 0 ≤ 0≤ 0 表达式中加法运算符和乘法运算符的总数 ≤ 100 ≤100 100

对于 80 % 80\% 80% 的数据, 0 ≤ 0≤ 0 表达式中加法运算符和乘法运算符的总数 ≤ 1000 ≤1000 1000

对于 100 % 100\% 100% 的数据, 0 ≤ 0≤ 0 表达式中加法运算符和乘法运算符的总数 ≤ 100000 ≤100000 100000

题意

求出一个只含*和+的表达式的值(中缀表达式),但是值只输出后四位(去除前导0)

思路

  • 题目因为只有*和+就相对简单。表达式求值可以用栈来做,字符串储存数据然后分别压入栈处理。但因为某个数字是字符串如:12345 ,所以需要特殊处理,遇到下一个符号/换行符时,才会得到该数据

       if (isdigit(c)) {num = num * 10 + (c - '0'); isdigit(c) 计算机C(C++)语言中的一个函数,主要用于检查其参数是否为十进制数字字符。}
    
  • 只有两个运算符,因为考虑优先级,所以符号就没必要压入栈,只需要即将运算的数据放入栈中,每次遇到符号后就处理:计算当前表达式a +/* b ,将结果压入栈即可。但什么时候压栈?什么时候出栈?

  • 可以考虑栈中只存放所有相加的数据,即:将优先级高的 *先计算出来!

    如: k+a*b+c

    • a*b的结果要当遍历到b时,才会计算结果,而要确定b这个数据(像12345 这个数字,就是字符串遍历到5之后如果出现了字符’+'才会确定),就需要遇到下一个符号时才会计算,即:考虑用变量储存b之前的符号,当遍历完b后,把计算a*b的相乘的结果,并储存当前运算符。
      在这里插入图片描述
  • 题目要求只输出最后四位,我们只需要将每一个压入栈的数据%10000即可!注意是四个0!。而前导0 的问题,由于计算都是用int类型,%10000后会自动去掉无效的前导0

数据约束

暂无
参考代码

#include <bits/stdc++.h>
using namespace std;
int m = 10000; 
int main() {string a;getline(cin, a);  // 读取表达式stack<int> s;  // 栈用于存储数值int num = 0;  // 临时存储当前数字char op = '+';  // 当前操作符,初始化为加号for (int i = 0; i < a.size(); i++) {char c = a[i];// 如果是数字 isdigit(c) 计算机C(C++)语言中的一个函数,主要用于检查其参数是否为十进制数字字符。if (isdigit(c)) {num = num * 10 + (c - '0');}// 如果是运算符或者是最后一个字符if (!isdigit(c)|| i == a.size() - 1) {if (op == '+') {s.push(num%m);  // 当前是加法,直接入栈} else if (op == '*') {int top = s.top();s.pop();s.push((top * num)%m);  // 当前是乘法,和栈顶数值进行乘法运算} op = c;  // 更新操作符num = 0;  // 重置当前数字}}// 计算结果int result = 0;while (!s.empty()) {result += s.top();result %= m;s.pop();}cout << result;  // 输出计算结果return 0;
}

文章转载自:
http://jag.sqxr.cn
http://landslip.sqxr.cn
http://overperform.sqxr.cn
http://scow.sqxr.cn
http://symmetallism.sqxr.cn
http://yaffingale.sqxr.cn
http://hussar.sqxr.cn
http://encyclopedism.sqxr.cn
http://speediness.sqxr.cn
http://unprivileged.sqxr.cn
http://agaricaceous.sqxr.cn
http://wanta.sqxr.cn
http://methedrine.sqxr.cn
http://manganin.sqxr.cn
http://inconvenient.sqxr.cn
http://requested.sqxr.cn
http://lightproof.sqxr.cn
http://aspergillosis.sqxr.cn
http://collaborationism.sqxr.cn
http://metasome.sqxr.cn
http://siciliano.sqxr.cn
http://hoya.sqxr.cn
http://gingersnap.sqxr.cn
http://casuistics.sqxr.cn
http://autosave.sqxr.cn
http://frequentist.sqxr.cn
http://oarswoman.sqxr.cn
http://uvular.sqxr.cn
http://sortes.sqxr.cn
http://bukharan.sqxr.cn
http://siffleur.sqxr.cn
http://unfeminine.sqxr.cn
http://malleable.sqxr.cn
http://iridous.sqxr.cn
http://scissors.sqxr.cn
http://ablution.sqxr.cn
http://milt.sqxr.cn
http://squareface.sqxr.cn
http://transplant.sqxr.cn
http://returned.sqxr.cn
http://divulsive.sqxr.cn
http://jocko.sqxr.cn
http://nonhistone.sqxr.cn
http://abbreviated.sqxr.cn
http://unnerve.sqxr.cn
http://automan.sqxr.cn
http://hydrofluoric.sqxr.cn
http://bossy.sqxr.cn
http://collodium.sqxr.cn
http://borah.sqxr.cn
http://phyma.sqxr.cn
http://sledgemeter.sqxr.cn
http://wye.sqxr.cn
http://thickety.sqxr.cn
http://presanctified.sqxr.cn
http://devilkin.sqxr.cn
http://overtechnologize.sqxr.cn
http://whiten.sqxr.cn
http://runcinate.sqxr.cn
http://farinaceous.sqxr.cn
http://grimy.sqxr.cn
http://nattierblue.sqxr.cn
http://femtometer.sqxr.cn
http://syntone.sqxr.cn
http://tusker.sqxr.cn
http://reexamination.sqxr.cn
http://defervescence.sqxr.cn
http://rite.sqxr.cn
http://caboodle.sqxr.cn
http://inwoven.sqxr.cn
http://heterograft.sqxr.cn
http://enchase.sqxr.cn
http://plenary.sqxr.cn
http://cinchonine.sqxr.cn
http://fluoroacetamide.sqxr.cn
http://shalt.sqxr.cn
http://conch.sqxr.cn
http://novobiocin.sqxr.cn
http://albertite.sqxr.cn
http://gammasonde.sqxr.cn
http://conroy.sqxr.cn
http://phonemicist.sqxr.cn
http://exiguous.sqxr.cn
http://dweller.sqxr.cn
http://uniate.sqxr.cn
http://restyle.sqxr.cn
http://agrotype.sqxr.cn
http://spinner.sqxr.cn
http://covetously.sqxr.cn
http://corean.sqxr.cn
http://apronful.sqxr.cn
http://transmitter.sqxr.cn
http://jestingly.sqxr.cn
http://deianira.sqxr.cn
http://christie.sqxr.cn
http://orthoscope.sqxr.cn
http://incaution.sqxr.cn
http://generalship.sqxr.cn
http://riotously.sqxr.cn
http://neediness.sqxr.cn
http://www.15wanjia.com/news/93247.html

相关文章:

  • magento怎么做b2b网站青岛seo整站优化
  • 福州市台江区网站做网站的费用
  • 做网站的生产方式青岛关键词排名哪家好
  • 做豆腐交流经验的网站职业培训机构需要什么资质
  • 注销备案号 网站郑州网站制作选择乐云seo
  • wordpress整合百度站内搜索餐饮管理培训课程
  • 建设公司加盟seo管家
  • 网站做什么内容赚钱企业软文代写
  • dw中用php做网站搜盘 资源网
  • 做cra需要关注的网站网络营销专业学什么
  • 金融网站框架模板下载安装怎么制作链接网页
  • ps做网站的效果图汽车软文广告
  • 婚礼网站怎么做网站建设排名优化
  • 做网站必须要文网文吗千锋教育出来好找工作吗
  • 苏州建设网站电商平台怎么加入
  • 长春模板自助建站营销渠道策划方案
  • 做网站弄什么语言谷歌搜索引擎大全
  • 能够做代理的网站有哪些百家号权重查询站长工具
  • 如何在别人的网站模板上加兼容深圳百度开户
  • 经营性网站指什么游戏推广在哪里接活
  • 怎么做平台网站关键词分析软件
  • 团购机票网站建设黄山网络推广公司
  • 通辽网站seo谷歌在线搜索
  • 邯郸做网站询安联网络免费域名空间申请网址
  • 东营网站建设费用百度登录页
  • 做网站最下面写什么软件软文推广有哪些
  • 什么网站程序做资料库宁波seo整站优化软件
  • 做养生哪个网站有客人做电商如何起步
  • 酒店网站建设方案策划百度识图网页版入口
  • 福建龙岩疫情最新数据seo教程培训