惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

T
Tenable Blog
Last Week in AI
Last Week in AI
P
Proofpoint News Feed
Engineering at Meta
Engineering at Meta
H
Help Net Security
F
Fortinet All Blogs
MyScale Blog
MyScale Blog
宝玉的分享
宝玉的分享
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
博客园 - 司徒正美
量子位
N
Netflix TechBlog - Medium
Apple Machine Learning Research
Apple Machine Learning Research
小众软件
小众软件
Recorded Future
Recorded Future
博客园 - 三生石上(FineUI控件)
Vercel News
Vercel News
aimingoo的专栏
aimingoo的专栏
I
InfoQ
Microsoft Security Blog
Microsoft Security Blog
Scott Helme
Scott Helme
The Last Watchdog
The Last Watchdog
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
IT之家
IT之家
AI
AI
WordPress大学
WordPress大学
Security Archives - TechRepublic
Security Archives - TechRepublic
Google Online Security Blog
Google Online Security Blog
U
Unit 42
V2EX - 技术
V2EX - 技术
MongoDB | Blog
MongoDB | Blog
Schneier on Security
Schneier on Security
博客园 - Franky
H
Heimdal Security Blog
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Jina AI
Jina AI
W
WeLiveSecurity
P
Privacy & Cybersecurity Law Blog
Cloudbric
Cloudbric
B
Blog RSS Feed
N
News | PayPal Newsroom
S
Securelist
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
I
Intezer
Hacker News - Newest:
Hacker News - Newest: "LLM"
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
博客园_首页
罗磊的独立博客
H
Hackread – Cybersecurity News, Data Breaches, AI and More
雷峰网
雷峰网

博客园 - 湖东

土鸡钵 工作中常见的一些英语(三) 工作中常见的一些英语(二) IDEA Community环境搭建笔记 查死锁 Jemeter使用 记录 ASP.NET并发处理 如何管理一个散漫的团队 平板开发常用框架了解 关于团队管理的一些好贴 maven项目对象配置文件 pom.xml 解析(l转载) eclipse + maven +tomcat 开发环境搭建 正则表达式30分钟入门教程(转载) 前端进阶知识汇总 速度提高几百倍,记一次数据结构在实际工作中的运用(转) SQL Server应用模式之OLTP系统性能分析(转载网上的文章并结合自已的实例 ,部分脚本有做调整 ) SQL Server I/O 问题的诊断分析(转载) 一次性能优化实战经历 Sqlserver:动态性能视图:sys.dm_os_wait_stats
java算法计算一元一次方程
湖东 · 2020-12-14 · via 博客园 - 湖东

java算法计算一元一次方程是昨年10月写的了,最近想写写算法就把它整理出来了。

核心思想是将方程转化为:aX+b = cX+d 的形式再进行计算,转化的思想是根据符号的优先级一层一层的分割。分割规则是先把+号能分割完的分割完,再把-号能分割完的分割完,最后分割*/号,不能从括号里面分割。具体过程如下:

方程:-3-12+2*(-7+5x)=-3-4+3*(6x+9)+10*3-20-30,以左边为例:

先根据 + 号 分割,结果为:

左:-3-12                              +                             右: 2*(-7+5x)

左边只能根据 - 号分割,右边根据*号分割

左:左:-3    -    右:12         +                             右: 左:2         *       右:-7+5x

左边,右边都是 aX+b 形式直接计算,-3也是aX+b形式(a=0,b=-3)

左:-15                                  +                             右:-14+10x

最后左侧将转化为:10x-29

完整代码如下:

/**
 * Created by LL on 2016/10/13.
 */
public class yiyuanyicifangcheng {

    public static void main(String[] args) {
        String string="-3-12+2*(-7+5x)=-3-4+3*(6x+9)+10*3-20-30";
        double result = calculate(string);
        System.out.println("计算结果:x = "+result);
    }

    /**
     * 此类方法用于将字符串化为: aX+b 结构,结果返回a,b
     * @param str:需要计算的字符串
     */
    public static Result translate(String str) {
        str=deleteKH(str);
        char[] chars = str.toCharArray();
        

运行结果:

这里写图片描述