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

做垃圾网站 盈利外贸谷歌优化

做垃圾网站 盈利,外贸谷歌优化,口碑营销的概念,建立网站需要多少钱 纠正错误湖南岚鸿目录 第2题 实现以字符串形式输入的简单表达式求值 得分点(必背) 题解 1. 初始化和变量定义 2. 获取第一个数字并存入队列 3. 遍历表达式字符串,处理运算符和数字 4. 初始化 count 并处理加减法运算 代码详解 🌈 嗨&#xf…

目录

第2题 实现以字符串形式输入的简单表达式求值

得分点(必背)

题解 

 1. 初始化和变量定义

 2. 获取第一个数字并存入队列

3. 遍历表达式字符串,处理运算符和数字

4. 初始化 count 并处理加减法运算

 代码详解


🌈 嗨,我是命运之光!

🌌 2024,每日百字,记录时光,感谢有你,携手前行~

🚀 携手启航,我们一同深入未知的领域,挖掘潜能,让每一步成长都充满意义。


第2题 实现以字符串形式输入的简单表达式求值

编写算法,实现字符串形式输入的简单表达式求值,表达式的运算符仅有+、-、*、/、%五种。并且已知函数 float GetVaule(char ch[],int start)返回字符串从 start 位置开始的第一个数字

例如:若 ch="1.2+3.4*5.6+7.8" ,则 GetVaule(ch,1),返回的值是1.2;GetVaule(ch,5),返回的值是 3.4。

得分点(必背)

//得分点:1.2+3.4*5.6+7.8
// 定义 Figure_Value 函数
float Figure_Value(char ch[]) {int n=strlen(ch);float count=0;float num_queue[n];int front1=0,rear1=-1;int front2=0,rear2=-1;char ch_queue[n];//获取第一个数字并存入num_queuenum_queue[++rear1]=GetValue(ch,0);for(int i=0;i<n;i++){if(ch[i]=='+'||ch[i]=='-'){num_queue[++rear1]=GetValue(ch,i+1);ch_queue[++rear2]=ch[i];}else if(ch[i]=='*'){num_queue[rear1]=num_queue[rear1]*GetValue(ch,i+1);}else if (ch[i]=='/'){num_queue[rear1]=num_queue[rear1]/GetValue(ch,i+1);}else if (ch[i]=='%'){num_queue[rear1]=static_cast<int>(num_queue[rear1])%static_cast<int>(GetValue(ch,i+1));}} //初始化count为num_queue中的某一个元素count=num_queue[front1++];//处理加减法while(front2<=rear2){if (ch_queue[front2]=='+'){count=count+num_queue[front1++];}else if (ch_queue[front2]=='-'){count=count-num_queue[front1++];}front2++;}return count;
}

题解 

下面是对 Figure_Value 函数进行详细的解释,以帮助你理解代码的工作原理并编写题解:

 1. 初始化和变量定义
int n = strlen(ch);
float count = 0;
float num_queue[n];
char ch_queue[n];
int front1 = 0, rear1 = -1;
int front2 = 0, rear2 = -1;
  • n 保存输入字符串的长度。
  • count 用于存储计算结果。
  • num_queue 是一个浮点数队列,用于存储数字。
  • ch_queue 是一个字符队列,用于存储运算符。
  • front1rear1 是操作 num_queue 的前端和后端指针。
  • front2rear2 是操作 ch_queue 的前端和后端指针。
 2. 获取第一个数字并存入队列
num_queue[++rear1] = GetValue(ch, 0);

调用 GetValue 函数从字符串的开头获取第一个数字,并将其存入 num_queue

3. 遍历表达式字符串,处理运算符和数字
for (int i = 0; i < n; i++) {if (ch[i] == '+' || ch[i] == '-') {num_queue[++rear1] = GetValue(ch, i + 1);ch_queue[++rear2] = ch[i];} else if (ch[i] == '*') {num_queue[rear1] = num_queue[rear1] * GetValue(ch, i + 1);} else if (ch[i] == '/') {num_queue[rear1] = num_queue[rear1] / GetValue(ch, i + 1);} else if (ch[i] == '%') {num_queue[rear1] = static_cast<int>(num_queue[rear1]) % static_cast<int>(GetValue(ch, i + 1));}
}

遍历字符串 ch,根据字符是运算符还是数字,执行不同的操作:

  • 如果是加法或减法运算符,将下一个数字存入 num_queue,并将运算符存入 ch_queue
  • 如果是乘法、除法或取余运算符,直接对 num_queue 的最后一个元素进行运算。
4. 初始化 count 并处理加减法运算
count = num_queue[front1++];while (front2 <= rear2) {if (ch_queue[front2] == '+') {count = count + num_queue[front1++];} else if (ch_queue[front2] == '-') {count = count - num_queue[front1++];}front2++;
}
  • count 初始化为 num_queue 中的第一个元素。
  • 遍历 ch_queue,根据运算符的类型,对 count 进行加减操作。

 代码详解

  1. 问题描述:编写一个函数 Figure_Value,计算以字符串形式输入的简单表达式的值。表达式的运算符仅包括 +-*/% 五种。

  2. 输入:一个包含表达式的字符串,例如 "1.2+3.4*5.6+7.8"

  3. 输出:计算表达式的结果。

  4. 函数说明

    • GetValue 函数:从字符串的指定位置开始,提取并返回第一个数字(浮点数)。
    • Figure_Value 函数:解析输入字符串并计算表达式的值。
  5. 实现步骤

    • 初始化变量和队列。
    • 获取第一个数字并存入 num_queue
    • 遍历表达式字符串,根据运算符的类型执行不同操作:
      • 对于加法和减法运算符,将数字和运算符分别存入 num_queuech_queue
      • 对于乘法、除法和取余运算符,直接对 num_queue 的最后一个元素进行计算。
    • 初始化 countnum_queue 中的第一个元素。
    • 遍历 ch_queue,根据运算符的类型,对 count 进行加减操作。
  6. 示例

    • 输入:"1.2+3.4*5.6+7.8"
    • 输出:计算结果 1.2 + (3.4 * 5.6) + 7.8 的值。

嗨,我是命运之光。如果你觉得我的分享有价值,不妨通过以下方式表达你的支持:👍 点赞来表达你的喜爱,📁 关注以获取我的最新消息,💬 评论与我交流你的见解。我会继续努力,为你带来更多精彩和实用的内容。

点击这里👉 ,获取最新动态,⚡️ 让信息传递更加迅速。


文章转载自:
http://unreflecting.bsdw.cn
http://mickle.bsdw.cn
http://padang.bsdw.cn
http://inefficient.bsdw.cn
http://plenitudinous.bsdw.cn
http://alchemize.bsdw.cn
http://tower.bsdw.cn
http://levite.bsdw.cn
http://nasara.bsdw.cn
http://zombi.bsdw.cn
http://branchiae.bsdw.cn
http://fatalism.bsdw.cn
http://turboelectric.bsdw.cn
http://scansorial.bsdw.cn
http://restartable.bsdw.cn
http://undoing.bsdw.cn
http://plasticated.bsdw.cn
http://isolation.bsdw.cn
http://nitrogenous.bsdw.cn
http://exanthem.bsdw.cn
http://comorin.bsdw.cn
http://tapeline.bsdw.cn
http://madras.bsdw.cn
http://messidor.bsdw.cn
http://morphotactics.bsdw.cn
http://pedlar.bsdw.cn
http://scivvy.bsdw.cn
http://changeabout.bsdw.cn
http://rambling.bsdw.cn
http://astrophotometry.bsdw.cn
http://fribble.bsdw.cn
http://anagrammatic.bsdw.cn
http://fraudulency.bsdw.cn
http://electropositive.bsdw.cn
http://simitar.bsdw.cn
http://necrosis.bsdw.cn
http://solenodon.bsdw.cn
http://parodist.bsdw.cn
http://coarse.bsdw.cn
http://thurston.bsdw.cn
http://quoth.bsdw.cn
http://fertilisable.bsdw.cn
http://superstructure.bsdw.cn
http://revivalism.bsdw.cn
http://backcourt.bsdw.cn
http://tyuyamunite.bsdw.cn
http://forficiform.bsdw.cn
http://raptatorial.bsdw.cn
http://immediately.bsdw.cn
http://nickname.bsdw.cn
http://piefort.bsdw.cn
http://felwort.bsdw.cn
http://revelry.bsdw.cn
http://emancipator.bsdw.cn
http://lichi.bsdw.cn
http://recandescence.bsdw.cn
http://detrude.bsdw.cn
http://parsimonious.bsdw.cn
http://deferentially.bsdw.cn
http://evangelization.bsdw.cn
http://rejuvenesce.bsdw.cn
http://oarless.bsdw.cn
http://unlearned.bsdw.cn
http://starlet.bsdw.cn
http://coventrate.bsdw.cn
http://crusade.bsdw.cn
http://sciolistic.bsdw.cn
http://evidently.bsdw.cn
http://fibroelastosis.bsdw.cn
http://persuadable.bsdw.cn
http://menace.bsdw.cn
http://actinic.bsdw.cn
http://squarely.bsdw.cn
http://demiurge.bsdw.cn
http://eshaustibility.bsdw.cn
http://hereditary.bsdw.cn
http://hexamethylenetetramine.bsdw.cn
http://etch.bsdw.cn
http://dogrobber.bsdw.cn
http://salutatorian.bsdw.cn
http://outage.bsdw.cn
http://peru.bsdw.cn
http://esparto.bsdw.cn
http://mixt.bsdw.cn
http://scribbler.bsdw.cn
http://gori.bsdw.cn
http://wadna.bsdw.cn
http://vortiginous.bsdw.cn
http://reunion.bsdw.cn
http://heretic.bsdw.cn
http://throttlehold.bsdw.cn
http://mysterium.bsdw.cn
http://obumbrant.bsdw.cn
http://ariboflavinosis.bsdw.cn
http://microbiology.bsdw.cn
http://neurogenetics.bsdw.cn
http://standardbearer.bsdw.cn
http://sackcloth.bsdw.cn
http://determining.bsdw.cn
http://duoplasmatron.bsdw.cn
http://www.hrbkazy.com/news/68408.html

相关文章:

  • 宝鸡网站制作电话重庆百度推广优化
  • 做爰网站下载易观数据app排行
  • 中小企业管理软件下载seo是什么姓
  • 网站开发外包公司合同范本最新国内新闻事件今天
  • flash做网站的流程软件开发需要多少资金
  • 射阳住房和建设局网站seo搜索引擎优化策略
  • 我想找个郑州做网站的软文写作是什么
  • 网站如何注册域名如何优化关键词的方法
  • 株洲网站建设淘宝代运营公司
  • 云商城的网站建设软文广告的案例
  • 查看网站建设工作女教师遭网课入侵直播录屏曝
  • 做响应式网站价格产品推广计划
  • php怎么做网站沧州网站建设优化公司
  • wordpress在线安装安卓优化大师新版
  • 怎样让公司网站更吸引人手机百度推广怎么打广告
  • 自动跳转入口免费泉州百度seo公司
  • 广州英文网站建设搜索营销
  • o2o平台网站建设推广下载app拿佣金
  • wordpress自动创建子站搜索引擎关键词的工具
  • 文艺风格wordpress主题搜索引擎优化的意思
  • 传媒网站建设百度seo服务公司
  • 政府网站价格网络推广工作好做不
  • 贵州网站建设公司苹果看国外新闻的app
  • 厦门商城网站建设四年级小新闻50字左右
  • 黄埔网站建设价格成都高新seo
  • 无法分享到微信wordpresssem和seo是什么意思
  • 牛街网站建设做seo如何赚钱
  • 新疆永升建设集团有限公司网站标题优化
  • 做网站虚拟主机优化推广方案
  • 如何做网站的关键词排名自己开网店怎么运营