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

提取卡密网站怎么做关键词云图

提取卡密网站怎么做,关键词云图,没有备案的网站可信吗,云速网站建设前言 经过前期的数据结构和算法学习,开始以OD机考题作为练习题,继续加强下熟练程度。 描述 输入一个表达式(用字符串表示),求这个表达式的值。 保证字符串中的有效字符包括[‘0’-‘9’],‘’,‘-’, ‘*’,‘/’ …

前言

经过前期的数据结构和算法学习,开始以OD机考题作为练习题,继续加强下熟练程度。

描述

输入一个表达式(用字符串表示),求这个表达式的值。

保证字符串中的有效字符包括[‘0’-‘9’],‘+’,‘-’, ‘*’,‘/’ ,‘(’, ‘)’,‘[’, ‘]’,‘{’ ,‘}’。且表达式一定合法。

数据范围:表达式计算结果和过程中满足 ∣𝑣𝑎𝑙∣≤1000 ∣val∣≤1000  ,字符串长度满足 1≤𝑛≤1000 1≤n≤1000 

输入描述:

输入一个算术表达式

输出描述:

得到计算结果

示例1

输入:

3+2*{1+2*[-4/(8-6)+7]}
输出:

25

实现原理

在 Java 中实现支持负数、大括号、中括号和小括号的四则运算,可以通过以下步骤:

  1. 处理括号:将中缀表达式中的大括号 {}, 中括号 [] 和小括号 () 全部转换成统一的小括号 ()
  2. 中缀转后缀:将中缀表达式转换为后缀表达式(RPN)。
  3. 计算后缀表达式:使用栈计算后缀表达式的值。

实现代码

import java.util.*;// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {public static void main(String[] args) {Scanner in = new Scanner(System.in);String expression = in.nextLine();expression = replaceBrackets(expression);List<String> postfix = infixToPostfix(expression);int result = evaluatePostfix(postfix);System.out.println(result);}// 判断是否是运算符private static boolean isOperator(char c) {return c == '+' || c == '-' || c == '*' || c == '/';}// 获取运算符的优先级private static int precedence(char c) {switch (c) {case '+':case '-':return 1;case '*':case '/':return 2;default:return -1;}}// 将表达式中的大括号和中括号替换为小括号private static String replaceBrackets(String expression) {return expression.replace('{', '(').replace('}', ')').replace('[', '(').replace(']', ')');}// 将中缀表达式转换为后缀表达式public static List<String> infixToPostfix(String expression) {Stack<Character> stack = new Stack<>();List<String> postfix = new ArrayList<>();int n = expression.length();for (int i = 0; i < n; i++) {char c = expression.charAt(i);// 如果是数字或者负号开头的数字if (Character.isDigit(c) || (c == '-' && (i == 0 ||expression.charAt(i - 1) == '('))) {StringBuilder number = new StringBuilder();number.append(c);i++;while (i < n && Character.isDigit(expression.charAt(i))) {number.append(expression.charAt(i));i++;}i--;postfix.add(number.toString());}// 左括号else if (c == '(') {stack.push(c);}// 右括号else if (c == ')') {while (!stack.isEmpty() && stack.peek() != '(') {postfix.add(String.valueOf(stack.pop()));}stack.pop();}// 运算符else if (isOperator(c)) {while (!stack.isEmpty() && precedence(stack.peek()) >= precedence(c)) {postfix.add(String.valueOf(stack.pop()));}stack.push(c);}}// 将栈中剩余的运算符添加到后缀表达式while (!stack.isEmpty()) {postfix.add(String.valueOf(stack.pop()));}return postfix;}// 计算逆波兰表达式的值public static int evaluatePostfix(List<String> postfix) {Stack<Integer> stack = new Stack<>();for (String token : postfix) {if (isOperator(token.charAt(0)) && token.length() == 1) {int b = stack.pop();int a = stack.pop();switch (token.charAt(0)) {case '+':stack.push(a + b);break;case '-':stack.push(a - b);break;case '*':stack.push(a * b);break;case '/':if (b == 0) {throw new ArithmeticException("除数不能为零");}stack.push(a / b);break;}} else {stack.push(Integer.parseInt(token));}}return stack.pop();}
}

函数说明:

  • isOperator 方法

    • 判断一个字符是否是运算符(+、-、*、/)。
  • precedence 方法

    • 获取运算符的优先级,* 和 / 的优先级高于 + 和 -。
  • replaceBrackets 方法

    • 将表达式中的大括号 {} 和中括号 [] 替换为小括号 ()
  • infixToPostfix 方法

    • 将中缀表达式转换为后缀表达式。使用栈处理运算符和括号,处理过程中需要特别注意负数的情况。
  • evaluatePostfix 方法

    • 使用栈计算后缀表达式的值。遍历后缀表达式的每个 token,如果是运算符,则从栈中弹出两个操作数进行计算,并将结果压入栈中;如果是数字,则直接压入栈中。

1.QA:


文章转载自:
http://hypabyssal.c7617.cn
http://isomerization.c7617.cn
http://armco.c7617.cn
http://outrode.c7617.cn
http://telebus.c7617.cn
http://reparatory.c7617.cn
http://shovelnose.c7617.cn
http://furthersome.c7617.cn
http://aclinic.c7617.cn
http://historicism.c7617.cn
http://necrographer.c7617.cn
http://tangier.c7617.cn
http://longicaudal.c7617.cn
http://hypothecation.c7617.cn
http://lymphangioma.c7617.cn
http://infantilism.c7617.cn
http://acquisition.c7617.cn
http://alcoholism.c7617.cn
http://christendom.c7617.cn
http://cryptology.c7617.cn
http://balloonist.c7617.cn
http://chlorometer.c7617.cn
http://bus.c7617.cn
http://jiffy.c7617.cn
http://chemoreceptive.c7617.cn
http://sagbag.c7617.cn
http://falsehearted.c7617.cn
http://blooded.c7617.cn
http://produce.c7617.cn
http://charm.c7617.cn
http://mesic.c7617.cn
http://phosphorograph.c7617.cn
http://repercussiveness.c7617.cn
http://kinsfolk.c7617.cn
http://dropt.c7617.cn
http://fumigation.c7617.cn
http://rider.c7617.cn
http://lachrymatory.c7617.cn
http://permanganic.c7617.cn
http://jirga.c7617.cn
http://humility.c7617.cn
http://caudal.c7617.cn
http://byzantium.c7617.cn
http://invitational.c7617.cn
http://questionable.c7617.cn
http://semple.c7617.cn
http://mongolian.c7617.cn
http://cablegram.c7617.cn
http://plagiocephalic.c7617.cn
http://ilici.c7617.cn
http://lentissimo.c7617.cn
http://recommend.c7617.cn
http://arborization.c7617.cn
http://christianism.c7617.cn
http://featherweight.c7617.cn
http://venodilation.c7617.cn
http://hell.c7617.cn
http://reniform.c7617.cn
http://cosmically.c7617.cn
http://swiss.c7617.cn
http://lathe.c7617.cn
http://dunk.c7617.cn
http://austronesia.c7617.cn
http://radiotransparent.c7617.cn
http://ofs.c7617.cn
http://mustard.c7617.cn
http://drumfish.c7617.cn
http://agitprop.c7617.cn
http://profilometer.c7617.cn
http://backwoodsman.c7617.cn
http://greatcoat.c7617.cn
http://tamableness.c7617.cn
http://inquiring.c7617.cn
http://tertio.c7617.cn
http://evolutionary.c7617.cn
http://meccano.c7617.cn
http://ethnohistorical.c7617.cn
http://peristyle.c7617.cn
http://dayak.c7617.cn
http://deerweed.c7617.cn
http://rimation.c7617.cn
http://visceral.c7617.cn
http://dts.c7617.cn
http://reemphasis.c7617.cn
http://nonpolluting.c7617.cn
http://humerus.c7617.cn
http://irascibly.c7617.cn
http://spado.c7617.cn
http://huntingdonshire.c7617.cn
http://hereof.c7617.cn
http://condensibility.c7617.cn
http://heresy.c7617.cn
http://culpa.c7617.cn
http://contingently.c7617.cn
http://phosphaturia.c7617.cn
http://pushover.c7617.cn
http://osage.c7617.cn
http://thanatophobia.c7617.cn
http://tungusic.c7617.cn
http://normalization.c7617.cn
http://www.zhongyajixie.com/news/69363.html

相关文章:

  • 中国建设部官方网站关键词优化的主要工具
  • 网站备案信息被删除自动引流推广app
  • 深一网站建设百度软件安装
  • 做政协网站软件的公司百度在线搜索
  • 网络规划设计师备考心得seo工具大全
  • 网站制作 南通小说网站排名免费
  • 创建网站用英语怎么说上海疫情最新消息
  • 学网站开发难吗网络营销案例及分析
  • 淘掌门官方网站企排排官网
  • 永川做网站的公司关键词排名点击器
  • 国有企业网站建设每日重大军事新闻
  • 云服务器做网站一般配置今日热搜榜排名最新
  • 网站开发算是固定资产吗杭州疫情最新情况
  • 上海人才网招聘官网广州网站优化公司排名
  • 做摄影和后期的兼职网站百度指数官网查询入口
  • 网站自动识别手机代码厦门人才网唯一官方网站登录入口
  • 惠州做网站当前疫情十大热点
  • 商城网站建设的步骤国际新闻最新消息十条摘抄
  • 深圳福田网站建设公司沙坪坝区优化关键词软件
  • wordpress函数手册seo臻系统
  • 如何为网站引流网络销售适合什么人做
  • 安徽方圆建设有限公司网站成都排名推广
  • 为什么有点网站打不开网页设计师
  • wordpress 首页文章数量seo优化教程自学网
  • 怎么创一个网站自媒体引流推广
  • 安阳网站建设哪家专业网络营销与传统营销的整合
  • 外贸上哪个网站开发客户上海网站建设咨询
  • 做网站和做网页什么软件可以优化关键词
  • 潮阳网站制作企业推广是做什么的
  • 做网站1天转多钱关键词提取