荆州网站建设厂家,企业推广策略,网站背景视频是怎么做的,医院网站和公众号建设方案2025年天津大学计算机考研复试机试真题
2025年天津大学计算机考研复试上机真题
历年天津大学计算机考研复试上机真题
历年天津大学计算机考研复试机试真题
更多学校题目开源地址#xff1a;https://gitcode.com/verticallimit1/noobdream
N 诺 DreamJudge 题库#xff1…2025年天津大学计算机考研复试机试真题2025年天津大学计算机考研复试上机真题历年天津大学计算机考研复试上机真题历年天津大学计算机考研复试机试真题更多学校题目开源地址https://gitcode.com/verticallimit1/noobdreamN 诺 DreamJudge 题库输入 “学校名称” 即可筛选该校历年机试真题题目均在考纲范围内按难度自动排序。还可搭配《计算机考研机试攻略》刷题书中题目可通过题号直接在题库中查找。天津大学-计算表达式题目描述Time Limit: 1000 msMemory Limit: 256 mb输入字符串的中缀表达式包含‘’、‘-’、‘*’、‘/’、‘(’、‘)’输出运算结果。输入输出格式输入描述:字符串的中缀表达式输出描述:计算结果输入输出样例输入样例#:3(5-3)*2输出样例#:7代码一#include iostream#include vector#include algorithm#include iomanip#include set#include list#include string#include cmath#include stack#include map#include sstream#include queue#include bitset#include climitsusing namespace std;mapchar, intmapp{{,1},{-,1},{*,2},{/,2}};void fun(stackint nums, stackchar ops) {int b nums.top(); nums.pop();int a nums.top(); nums.pop();char op ops.top(); ops.pop();int result;if (op ) result a b;else if (op -)result a - b;else if (op *)result a * b;else result a / b;nums.push(result);}int main() {string s;while (cin s) {stackintnums;stackcharops;char op;for(int i0;is.size();i) {op s[i];if (s[i] 0 s[i] 9) {int num 0;while (i s.length() isdigit(s[i])) {num num * 10 (s[i] - 0);i;}i--;nums.push(num);}else if (op () {ops.push(op);}else if (op )) {while (!ops.empty() ops.top() ! () {fun(nums, ops);}if (!ops.empty()) {ops.pop();}}else {while (!ops.empty() ops.top() ! ( mapp[ops.top()]mapp[op]) {fun(nums, ops);}ops.push(op);}}while (!ops.empty()) {fun(nums, ops);}cout nums.top() endl;}return 0;}代码二#includeiostream#includeunordered_map#includealgorithm#includestring#includestackusing namespace std;stackint num;stackchar fu;unordered_mapchar, int h{ {,1},{-,1},{*,2},{/,2} };void jisuan() {int num1 num.top();num.pop();int num2 num.top();num.pop();char f fu.top();fu.pop();int n 0;if (f )n num1 num2;if (f -)n num2 - num1;if (f *)n num1 * num2;if (f /)n num2 / num1;num.push(n);}int main() {string s;cin s;for (int i 0; i s.size(); i) {if (isdigit(s[i])) {int j i, x 0;while (j s.size() isdigit(s[j])) {x x * 10 s[j] - 0;j;}num.push(x);i j - 1;}else if (s[i] () {fu.push(s[i]);}else if (s[i] )) {while (fu.top() ! () {jisuan();}fu.pop();}else {while (fu.size() 0 h[s[i]] h[fu.top()]) {jisuan();}fu.push(s[i]);}}while (fu.size())jisuan();cout num.top() endl;return 0;}代码三#includebits/stdc.husing namespace std;struct li{//方便存储多位数字char ch$;int number;};int main(){vectorlires;//存后缀表达式stackintsta;//后缀表达式求值操作栈mapchar,int m;m[]1;m[-]1;m[*]2;m[/]2;m[^]3;string str;cinstr;int lenstr.length();stackchars;//中缀转后缀操作栈for(int i0;ilen;){//中缀转后缀if(str[i]0str[i]9){//数字string cc;while(str[i]0str[i]9){ccstr[i];i;}int numstoi(cc);li temp;temp.numbernum;res.push_back(temp);continue;}else if(str[i](){//左括号s.push(str[i]);}else if(str[i])){//右括号while(s.top()!(){li temp;temp.chs.top();res.push_back(temp);s.pop();}s.pop();}else{//-*/^运算符if(!s.empty()){if(s.top()!(){int bm[str[i]];int am[s.top()];while(ab){li temp;temp.chs.top();res.push_back(temp);s.pop();if(s.empty()){break;}if(s.top()(){break;}int am[s.top()];}}}s.push(str[i]);}i;}while(!s.empty()){li temp;temp.chs.top();res.push_back(temp);s.pop();}//后缀表达式求值for(int i0;ires.size();i){if(res[i].ch$){//数字sta.push(res[i].number);}else{//运算符int bsta.top();sta.pop();int asta.top();sta.pop();int c;if(res[i].ch){cab;}else if(res[i].ch-){ca-b;}else if(res[i].ch*){ca*b;}else if(res[i].ch/){ca/b;}else if(res[i].ch^){c(int)pow(a,b);}sta.push(c);}}coutsta.top();return 0;}