├── Core algorithm.cpp ├── Graphical source code ├── 1.jpeg ├── 1.jpg ├── 2.jpg ├── 3.jpg ├── Chemical Balancer.pro ├── Chemical Balancer.pro.user ├── Chemical Balancer.pro.user.12b2305 ├── form.cpp ├── form.h ├── form.ui ├── icon.ico ├── main.cpp ├── mainwindow.cpp ├── mainwindow.h ├── mainwindow.ui ├── res.qrc ├── style.qss └── yjtp (1).ico ├── LICENSE ├── README-cn.md └── README.md /Core algorithm.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AMT-J/Chemical-Balancer/bdff545006108a02709a6a5e9c44b7a8932c28d5/Core algorithm.cpp -------------------------------------------------------------------------------- /Graphical source code/1.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AMT-J/Chemical-Balancer/bdff545006108a02709a6a5e9c44b7a8932c28d5/Graphical source code/1.jpeg -------------------------------------------------------------------------------- /Graphical source code/1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AMT-J/Chemical-Balancer/bdff545006108a02709a6a5e9c44b7a8932c28d5/Graphical source code/1.jpg -------------------------------------------------------------------------------- /Graphical source code/2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AMT-J/Chemical-Balancer/bdff545006108a02709a6a5e9c44b7a8932c28d5/Graphical source code/2.jpg -------------------------------------------------------------------------------- /Graphical source code/3.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AMT-J/Chemical-Balancer/bdff545006108a02709a6a5e9c44b7a8932c28d5/Graphical source code/3.jpg -------------------------------------------------------------------------------- /Graphical source code/Chemical Balancer.pro: -------------------------------------------------------------------------------- 1 | QT += core gui 2 | 3 | greaterThan(QT_MAJOR_VERSION, 4): QT += widgets 4 | 5 | CONFIG += c++11 6 | RC_ICONS = icon.ico 7 | 8 | # You can make your code fail to compile if it uses deprecated APIs. 9 | # In order to do so, uncomment the following line. 10 | #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 11 | 12 | SOURCES += \ 13 | form.cpp \ 14 | main.cpp \ 15 | mainwindow.cpp 16 | 17 | HEADERS += \ 18 | form.h \ 19 | mainwindow.h 20 | 21 | FORMS += \ 22 | form.ui \ 23 | mainwindow.ui 24 | 25 | # Default rules for deployment. 26 | qnx: target.path = /tmp/$${TARGET}/bin 27 | else: unix:!android: target.path = /opt/$${TARGET}/bin 28 | !isEmpty(target.path): INSTALLS += target 29 | 30 | RESOURCES += \ 31 | res.qrc 32 | -------------------------------------------------------------------------------- /Graphical source code/Chemical Balancer.pro.user: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | EnvironmentId 7 | {7c6d05e9-cefb-4916-9256-477883bfa959} 8 | 9 | 10 | ProjectExplorer.Project.ActiveTarget 11 | 0 12 | 13 | 14 | ProjectExplorer.Project.EditorSettings 15 | 16 | true 17 | false 18 | true 19 | 20 | Cpp 21 | 22 | CppGlobal 23 | 24 | 25 | 26 | QmlJS 27 | 28 | QmlJSGlobal 29 | 30 | 31 | 2 32 | UTF-8 33 | false 34 | 4 35 | false 36 | 80 37 | true 38 | true 39 | 1 40 | true 41 | false 42 | 0 43 | true 44 | true 45 | 0 46 | 8 47 | true 48 | 1 49 | true 50 | true 51 | true 52 | false 53 | 54 | 55 | 56 | ProjectExplorer.Project.PluginSettings 57 | 58 | 59 | -fno-delayed-template-parsing 60 | 61 | true 62 | 63 | 64 | 65 | ProjectExplorer.Project.Target.0 66 | 67 | Desktop Qt 5.14.2 MinGW 32-bit 68 | Desktop Qt 5.14.2 MinGW 32-bit 69 | qt.qt5.5142.win32_mingw73_kit 70 | 1 71 | 0 72 | 0 73 | 74 | D:/C++#QT/build-ChemistryCal-Desktop_Qt_5_14_2_MinGW_32_bit-Debug 75 | 76 | 77 | true 78 | QtProjectManager.QMakeBuildStep 79 | true 80 | 81 | false 82 | false 83 | false 84 | 85 | 86 | true 87 | Qt4ProjectManager.MakeStep 88 | 89 | false 90 | 91 | 92 | false 93 | 94 | 2 95 | Build 96 | Build 97 | ProjectExplorer.BuildSteps.Build 98 | 99 | 100 | 101 | true 102 | Qt4ProjectManager.MakeStep 103 | 104 | true 105 | clean 106 | 107 | false 108 | 109 | 1 110 | Clean 111 | Clean 112 | ProjectExplorer.BuildSteps.Clean 113 | 114 | 2 115 | false 116 | 117 | Debug 118 | Qt4ProjectManager.Qt4BuildConfiguration 119 | 2 120 | 121 | 122 | D:/C++#QT/build-ChemistryCal-Desktop_Qt_5_14_2_MinGW_32_bit-Release 123 | 124 | 125 | true 126 | QtProjectManager.QMakeBuildStep 127 | false 128 | 129 | false 130 | false 131 | true 132 | 133 | 134 | true 135 | Qt4ProjectManager.MakeStep 136 | 137 | false 138 | 139 | 140 | false 141 | 142 | 2 143 | Build 144 | Build 145 | ProjectExplorer.BuildSteps.Build 146 | 147 | 148 | 149 | true 150 | Qt4ProjectManager.MakeStep 151 | 152 | true 153 | clean 154 | 155 | false 156 | 157 | 1 158 | Clean 159 | Clean 160 | ProjectExplorer.BuildSteps.Clean 161 | 162 | 2 163 | false 164 | 165 | Release 166 | Qt4ProjectManager.Qt4BuildConfiguration 167 | 0 168 | 169 | 170 | D:/C++#QT/build-ChemistryCal-Desktop_Qt_5_14_2_MinGW_32_bit-Profile 171 | 172 | 173 | true 174 | QtProjectManager.QMakeBuildStep 175 | true 176 | 177 | false 178 | true 179 | true 180 | 181 | 182 | true 183 | Qt4ProjectManager.MakeStep 184 | 185 | false 186 | 187 | 188 | false 189 | 190 | 2 191 | Build 192 | Build 193 | ProjectExplorer.BuildSteps.Build 194 | 195 | 196 | 197 | true 198 | Qt4ProjectManager.MakeStep 199 | 200 | true 201 | clean 202 | 203 | false 204 | 205 | 1 206 | Clean 207 | Clean 208 | ProjectExplorer.BuildSteps.Clean 209 | 210 | 2 211 | false 212 | 213 | Profile 214 | Qt4ProjectManager.Qt4BuildConfiguration 215 | 0 216 | 217 | 3 218 | 219 | 220 | 0 221 | Deploy 222 | Deploy 223 | ProjectExplorer.BuildSteps.Deploy 224 | 225 | 1 226 | ProjectExplorer.DefaultDeployConfiguration 227 | 228 | 1 229 | 230 | 231 | dwarf 232 | 233 | cpu-cycles 234 | 235 | 236 | 250 237 | 238 | -e 239 | cpu-cycles 240 | --call-graph 241 | dwarf,4096 242 | -F 243 | 250 244 | 245 | -F 246 | true 247 | 4096 248 | false 249 | false 250 | 1000 251 | 252 | true 253 | 254 | false 255 | false 256 | false 257 | false 258 | true 259 | 0.01 260 | 10 261 | true 262 | kcachegrind 263 | 1 264 | 25 265 | 266 | 1 267 | true 268 | false 269 | true 270 | valgrind 271 | 272 | 0 273 | 1 274 | 2 275 | 3 276 | 4 277 | 5 278 | 6 279 | 7 280 | 8 281 | 9 282 | 10 283 | 11 284 | 12 285 | 13 286 | 14 287 | 288 | 2 289 | 290 | Qt4ProjectManager.Qt4RunConfiguration:D:/C++#QT/git/Graphical source code/Chemical Balancer.pro 291 | D:/C++#QT/git/Graphical source code/Chemical Balancer.pro 292 | 293 | false 294 | 295 | false 296 | true 297 | true 298 | false 299 | false 300 | true 301 | 302 | D:/C++#QT/build-ChemistryCal-Desktop_Qt_5_14_2_MinGW_32_bit-Release 303 | 304 | 1 305 | 306 | 307 | 308 | ProjectExplorer.Project.Target.1 309 | 310 | Desktop Qt 5.14.2 MinGW 64-bit 311 | Desktop Qt 5.14.2 MinGW 64-bit 312 | qt.qt5.5142.win64_mingw73_kit 313 | 1 314 | 0 315 | 0 316 | 317 | D:/C++#QT/build-ChemistryCal-Desktop_Qt_5_14_2_MinGW_64_bit-Debug 318 | 319 | 320 | true 321 | QtProjectManager.QMakeBuildStep 322 | true 323 | 324 | false 325 | false 326 | false 327 | 328 | 329 | true 330 | Qt4ProjectManager.MakeStep 331 | 332 | false 333 | 334 | 335 | false 336 | 337 | 2 338 | Build 339 | Build 340 | ProjectExplorer.BuildSteps.Build 341 | 342 | 343 | 344 | true 345 | Qt4ProjectManager.MakeStep 346 | 347 | true 348 | clean 349 | 350 | false 351 | 352 | 1 353 | Clean 354 | Clean 355 | ProjectExplorer.BuildSteps.Clean 356 | 357 | 2 358 | false 359 | 360 | Debug 361 | Qt4ProjectManager.Qt4BuildConfiguration 362 | 2 363 | 364 | 365 | D:/C++#QT/build-ChemistryCal-Desktop_Qt_5_14_2_MinGW_64_bit-Release 366 | 367 | 368 | true 369 | QtProjectManager.QMakeBuildStep 370 | false 371 | 372 | false 373 | false 374 | true 375 | 376 | 377 | true 378 | Qt4ProjectManager.MakeStep 379 | 380 | false 381 | 382 | 383 | false 384 | 385 | 2 386 | Build 387 | Build 388 | ProjectExplorer.BuildSteps.Build 389 | 390 | 391 | 392 | true 393 | Qt4ProjectManager.MakeStep 394 | 395 | true 396 | clean 397 | 398 | false 399 | 400 | 1 401 | Clean 402 | Clean 403 | ProjectExplorer.BuildSteps.Clean 404 | 405 | 2 406 | false 407 | 408 | Release 409 | Qt4ProjectManager.Qt4BuildConfiguration 410 | 0 411 | 412 | 413 | D:/C++#QT/build-ChemistryCal-Desktop_Qt_5_14_2_MinGW_64_bit-Profile 414 | 415 | 416 | true 417 | QtProjectManager.QMakeBuildStep 418 | true 419 | 420 | false 421 | true 422 | true 423 | 424 | 425 | true 426 | Qt4ProjectManager.MakeStep 427 | 428 | false 429 | 430 | 431 | false 432 | 433 | 2 434 | Build 435 | Build 436 | ProjectExplorer.BuildSteps.Build 437 | 438 | 439 | 440 | true 441 | Qt4ProjectManager.MakeStep 442 | 443 | true 444 | clean 445 | 446 | false 447 | 448 | 1 449 | Clean 450 | Clean 451 | ProjectExplorer.BuildSteps.Clean 452 | 453 | 2 454 | false 455 | 456 | Profile 457 | Qt4ProjectManager.Qt4BuildConfiguration 458 | 0 459 | 460 | 3 461 | 462 | 463 | 0 464 | Deploy 465 | Deploy 466 | ProjectExplorer.BuildSteps.Deploy 467 | 468 | 1 469 | ProjectExplorer.DefaultDeployConfiguration 470 | 471 | 1 472 | 473 | 474 | dwarf 475 | 476 | cpu-cycles 477 | 478 | 479 | 250 480 | 481 | -e 482 | cpu-cycles 483 | --call-graph 484 | dwarf,4096 485 | -F 486 | 250 487 | 488 | -F 489 | true 490 | 4096 491 | false 492 | false 493 | 1000 494 | 495 | true 496 | 497 | false 498 | false 499 | false 500 | false 501 | true 502 | 0.01 503 | 10 504 | true 505 | kcachegrind 506 | 1 507 | 25 508 | 509 | 1 510 | true 511 | false 512 | true 513 | valgrind 514 | 515 | 0 516 | 1 517 | 2 518 | 3 519 | 4 520 | 5 521 | 6 522 | 7 523 | 8 524 | 9 525 | 10 526 | 11 527 | 12 528 | 13 529 | 14 530 | 531 | 2 532 | 533 | Qt4ProjectManager.Qt4RunConfiguration:D:/C++#QT/git/Graphical source code/Chemical Balancer.pro 534 | D:/C++#QT/git/Graphical source code/Chemical Balancer.pro 535 | 536 | false 537 | 538 | false 539 | true 540 | true 541 | false 542 | false 543 | true 544 | 545 | D:/C++#QT/build-ChemistryCal-Desktop_Qt_5_14_2_MinGW_64_bit-Release 546 | 547 | 1 548 | 549 | 550 | 551 | ProjectExplorer.Project.TargetCount 552 | 2 553 | 554 | 555 | ProjectExplorer.Project.Updater.FileVersion 556 | 22 557 | 558 | 559 | Version 560 | 22 561 | 562 | 563 | -------------------------------------------------------------------------------- /Graphical source code/Chemical Balancer.pro.user.12b2305: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | EnvironmentId 7 | {12b2305a-485b-4198-9716-a11f3bbedd65} 8 | 9 | 10 | ProjectExplorer.Project.ActiveTarget 11 | 0 12 | 13 | 14 | ProjectExplorer.Project.EditorSettings 15 | 16 | true 17 | false 18 | true 19 | 20 | Cpp 21 | 22 | CppGlobal 23 | 24 | 25 | 26 | QmlJS 27 | 28 | QmlJSGlobal 29 | 30 | 31 | 2 32 | UTF-8 33 | false 34 | 4 35 | false 36 | 80 37 | true 38 | true 39 | 1 40 | false 41 | true 42 | false 43 | 0 44 | true 45 | true 46 | 0 47 | 8 48 | true 49 | false 50 | 1 51 | true 52 | true 53 | true 54 | *.md, *.MD, Makefile 55 | false 56 | true 57 | 58 | 59 | 60 | ProjectExplorer.Project.PluginSettings 61 | 62 | 63 | true 64 | false 65 | true 66 | true 67 | true 68 | true 69 | 70 | 71 | 0 72 | true 73 | 74 | true 75 | true 76 | Builtin.DefaultTidyAndClazy 77 | 2 78 | 79 | 80 | 81 | true 82 | 83 | 84 | 85 | 86 | ProjectExplorer.Project.Target.0 87 | 88 | Desktop 89 | Desktop Qt 5.15.2 MinGW 64-bit 90 | Desktop Qt 5.15.2 MinGW 64-bit 91 | qt.qt5.5152.win64_mingw81_kit 92 | 1 93 | 0 94 | 0 95 | 96 | 0 97 | E:\QT\Qt5.9Learning\chap09\build-ChemistryCal-Desktop_Qt_5_15_2_MinGW_64_bit-Debug 98 | E:/QT/Qt5.9Learning/chap09/build-ChemistryCal-Desktop_Qt_5_15_2_MinGW_64_bit-Debug 99 | 100 | 101 | true 102 | QtProjectManager.QMakeBuildStep 103 | false 104 | 105 | 106 | 107 | true 108 | Qt4ProjectManager.MakeStep 109 | 110 | 2 111 | Build 112 | Build 113 | ProjectExplorer.BuildSteps.Build 114 | 115 | 116 | 117 | true 118 | Qt4ProjectManager.MakeStep 119 | clean 120 | 121 | 1 122 | Clean 123 | Clean 124 | ProjectExplorer.BuildSteps.Clean 125 | 126 | 2 127 | false 128 | 129 | false 130 | 131 | Debug 132 | Qt4ProjectManager.Qt4BuildConfiguration 133 | 2 134 | 135 | 136 | E:\QT\Qt5.9Learning\chap09\build-ChemistryCal-Desktop_Qt_5_15_2_MinGW_64_bit-Release 137 | E:/QT/Qt5.9Learning/chap09/build-ChemistryCal-Desktop_Qt_5_15_2_MinGW_64_bit-Release 138 | 139 | 140 | true 141 | QtProjectManager.QMakeBuildStep 142 | false 143 | 144 | 145 | 146 | true 147 | Qt4ProjectManager.MakeStep 148 | 149 | 2 150 | Build 151 | Build 152 | ProjectExplorer.BuildSteps.Build 153 | 154 | 155 | 156 | true 157 | Qt4ProjectManager.MakeStep 158 | clean 159 | 160 | 1 161 | Clean 162 | Clean 163 | ProjectExplorer.BuildSteps.Clean 164 | 165 | 2 166 | false 167 | 168 | false 169 | 170 | Release 171 | Qt4ProjectManager.Qt4BuildConfiguration 172 | 0 173 | 0 174 | 175 | 176 | 0 177 | E:\QT\Qt5.9Learning\chap09\build-ChemistryCal-Desktop_Qt_5_15_2_MinGW_64_bit-Profile 178 | E:/QT/Qt5.9Learning/chap09/build-ChemistryCal-Desktop_Qt_5_15_2_MinGW_64_bit-Profile 179 | 180 | 181 | true 182 | QtProjectManager.QMakeBuildStep 183 | false 184 | 185 | 186 | 187 | true 188 | Qt4ProjectManager.MakeStep 189 | 190 | 2 191 | Build 192 | Build 193 | ProjectExplorer.BuildSteps.Build 194 | 195 | 196 | 197 | true 198 | Qt4ProjectManager.MakeStep 199 | clean 200 | 201 | 1 202 | Clean 203 | Clean 204 | ProjectExplorer.BuildSteps.Clean 205 | 206 | 2 207 | false 208 | 209 | false 210 | 211 | Profile 212 | Qt4ProjectManager.Qt4BuildConfiguration 213 | 0 214 | 0 215 | 0 216 | 217 | 3 218 | 219 | 220 | 0 221 | Deploy 222 | Deploy 223 | ProjectExplorer.BuildSteps.Deploy 224 | 225 | 1 226 | 227 | false 228 | ProjectExplorer.DefaultDeployConfiguration 229 | 230 | 1 231 | 232 | true 233 | true 234 | true 235 | 236 | 2 237 | 238 | Qt4ProjectManager.Qt4RunConfiguration:E:/QT/Qt5.9Learning/chap09/ChemistryCal/ChemistryCal.pro 239 | E:/QT/Qt5.9Learning/chap09/ChemistryCal/ChemistryCal.pro 240 | false 241 | true 242 | true 243 | false 244 | true 245 | E:/QT/Qt5.9Learning/chap09/build-ChemistryCal-Desktop_Qt_5_15_2_MinGW_64_bit-Release 246 | 247 | 1 248 | 249 | 250 | 251 | ProjectExplorer.Project.TargetCount 252 | 1 253 | 254 | 255 | ProjectExplorer.Project.Updater.FileVersion 256 | 22 257 | 258 | 259 | Version 260 | 22 261 | 262 | 263 | -------------------------------------------------------------------------------- /Graphical source code/form.cpp: -------------------------------------------------------------------------------- 1 | #include "form.h" 2 | #include "ui_form.h" 3 | 4 | Form::Form(QWidget *parent) : 5 | QWidget(parent), 6 | ui(new Ui::Form) 7 | { 8 | ui->setupUi(this); 9 | 10 | } 11 | 12 | Form::~Form() 13 | { 14 | delete ui; 15 | } 16 | -------------------------------------------------------------------------------- /Graphical source code/form.h: -------------------------------------------------------------------------------- 1 | #ifndef FORM_H 2 | #define FORM_H 3 | 4 | #include 5 | 6 | namespace Ui { 7 | class Form; 8 | } 9 | 10 | class Form : public QWidget 11 | { 12 | Q_OBJECT 13 | 14 | public: 15 | explicit Form(QWidget *parent = nullptr); 16 | ~Form(); 17 | 18 | private: 19 | Ui::Form *ui; 20 | }; 21 | 22 | #endif // FORM_H 23 | -------------------------------------------------------------------------------- /Graphical source code/form.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | Form 4 | 5 | 6 | true 7 | 8 | 9 | 10 | 0 11 | 0 12 | 630 13 | 370 14 | 15 | 16 | 17 | 18 | 630 19 | 370 20 | 21 | 22 | 23 | 24 | 630 25 | 370 26 | 27 | 28 | 29 | Help 30 | 31 | 32 | 33 | :/img/yjtp (1).ico:/img/yjtp (1).ico 34 | 35 | 36 | 37 | 38 | 39 | Qt::Horizontal 40 | 41 | 42 | 43 | 40 44 | 20 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | true 53 | 54 | 55 | 56 | 600 57 | 0 58 | 59 | 60 | 61 | 62 | 12 63 | 64 | 65 | 66 | 点击青蒿素以清除 67 | 68 | 输入化学方程规则如下: 69 | <equation> ::= <expr> "=" <expr> 70 | <expr> ::= <coef> <formula> | <expr> "+" <coef> <formula> 71 | <coef> ::= <digits> | "" | <electron> 72 | <electron>::= "<"<digits>"+>" | "<"<digits>"->" | "" 73 | <digits> ::= {<digit>} 74 | <digit> ::= "0" | "1" | ... | "9" 75 | <formula> ::= <term> <coef> | <formula> <term> <coef> 76 | <term> ::= <element> | "(" <formula> ")" | "[" <formula> "]" 77 | <element> ::= <uppercase> | <uppercase> <lowercase> 78 | <uppercase> ::= "A" | "B" | ... | "Z" 79 | <lowercase> ::= "a" | "b" | ... | "z" 80 | 81 | 82 | 83 | 84 | 85 | 86 | Qt::Horizontal 87 | 88 | 89 | 90 | 40 91 | 20 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | -------------------------------------------------------------------------------- /Graphical source code/icon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AMT-J/Chemical-Balancer/bdff545006108a02709a6a5e9c44b7a8932c28d5/Graphical source code/icon.ico -------------------------------------------------------------------------------- /Graphical source code/main.cpp: -------------------------------------------------------------------------------- 1 | #include "mainwindow.h" 2 | #include 3 | #include 4 | int main(int argc, char *argv[]) 5 | { 6 | QApplication::setAttribute(Qt::AA_EnableHighDpiScaling); 7 | QCoreApplication::setAttribute(Qt::AA_UseHighDpiPixmaps); 8 | qreal cx = GetSystemMetrics(SM_CXSCREEN); 9 | qreal scale = cx/1920*1.25; 10 | if (scale < 1) 11 | scale=1.0; 12 | qputenv("QT_SCALE_FACTOR", QString::number(scale).toLatin1()); 13 | //QGuiApplication::setHighDpiScaleFactorRoundingPolicy(Qt::HighDpiScaleFactorRoundingPolicy::PassThrough); 14 | QApplication a(argc, argv); 15 | MainWindow w; 16 | w.show(); 17 | return a.exec(); 18 | } 19 | -------------------------------------------------------------------------------- /Graphical source code/mainwindow.cpp: -------------------------------------------------------------------------------- 1 | #include "mainwindow.h" 2 | #include "ui_mainwindow.h" 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | MainWindow::MainWindow(QWidget *parent) 13 | : QMainWindow(parent) 14 | , ui(new Ui::MainWindow) 15 | { 16 | ui->setupUi(this); 17 | this->setAttribute(Qt::WA_TranslucentBackground);//设置窗口背景透明 18 | this->setWindowFlags(Qt::FramelessWindowHint); //设置无边框窗口 19 | form = new Form(); 20 | QFile qss(":/img/style.qss"); 21 | if(!qss.open(QFile::ReadOnly)) 22 | { 23 | qDebug()<<"Error: void setStyleQss()"<setStyleSheet(qss.readAll()); 27 | qss.close(); 28 | ui->leInput->installEventFilter(this); 29 | ui->leInput->setPlaceholderText("Enter here"); 30 | ui->leOutput->setPlaceholderText("The result are presented here"); 31 | } 32 | void MainWindow::paintEvent(QPaintEvent *event) 33 | { 34 | QPainter painter(this); 35 | painter.setRenderHint(QPainter::Antialiasing); // 反锯齿; 36 | painter.setBrush(QBrush(Qt::white)); 37 | //painter.setPen(Qt::transparent); 38 | QPen pen; 39 | pen.setColor(Qt::black); 40 | painter.setPen(pen); 41 | QRect rect = this->rect(); 42 | rect.setWidth(rect.width() - 1); 43 | rect.setHeight(rect.height() - 1); 44 | //painter.drawRoundedRect(rect, 10, 10); 45 | 46 | //也可用QPainterPath 绘制代替 painter.drawRoundedRect(rect, 15, 15); 47 | { 48 | QPainterPath painterPath; 49 | painterPath.addRoundedRect(rect, 15, 15); 50 | 51 | painter.drawPath(painterPath); 52 | //painterPath.drawPath(painterPath); 53 | } 54 | 55 | QWidget::paintEvent(event); 56 | } 57 | void MainWindow::mousePressEvent(QMouseEvent *event) 58 | { 59 | if (event->button() == Qt::LeftButton) 60 | last_mouse_position_ = event->globalPos(); 61 | } 62 | 63 | void MainWindow::mouseMoveEvent(QMouseEvent *event) 64 | { 65 | if (!event->buttons().testFlag(Qt::LeftButton)) 66 | return; 67 | const QPoint position = pos() + event->globalPos() - last_mouse_position_; //the position of mainfrmae + (current_mouse_position - last_mouse_position) 68 | move(position.x(), position.y()); 69 | last_mouse_position_ = event->globalPos(); 70 | } 71 | 72 | MainWindow::~MainWindow() 73 | { 74 | delete ui; 75 | } 76 | bool MainWindow::eventFilter(QObject *watched, QEvent *event) 77 | { 78 | if(event->type() == QKeyEvent::KeyPress){ 79 | QKeyEvent *keyEvent = static_cast(event); //转换事件类型 80 | QLineEdit *m_lineEdit = static_cast(watched); 81 | if(keyEvent->key() == Qt::Key_Enter || 82 | keyEvent->key() == Qt::Key_Return){ 83 | ui->leOutput->setText(cal(m_lineEdit->text())); 84 | return true; //返回true确认拦截该事件 85 | } 86 | } 87 | return false; //返回false对此次事件不进行拦截 88 | } 89 | 90 | QString MainWindow::cal(QString old) 91 | { 92 | InitAll(); 93 | rslt.clear(); 94 | s = old.toStdString(); 95 | s = DelSpace(s); 96 | InitElem(); 97 | for (register int i = 0; i < sum; i++) { 98 | if (!isdigit(s1[i][0])) 99 | d2[i] = 1; 100 | else { 101 | int x = 0, pos = 0; 102 | while (isdigit(s1[i][pos])) { 103 | x = (x << 1) + (x << 3) + int(char(s1[i][pos]) - '0'); 104 | pos++; 105 | } 106 | d2[i] = x; 107 | string m = to_string(x); 108 | s1[i] = s1[i].substr(m.length(), s1[i].length() - m.length()); 109 | } 110 | } 111 | ReadElem(); 112 | ToMatr(); 113 | solve(); 114 | if (flag) { 115 | int cnt = 0; 116 | for (cnt = 0; cnt < sum; cnt++) 117 | if (d1[cnt] != d2[cnt]) break; 118 | if (cnt < sum) { 119 | qDebug() << "配平结果: "; 120 | QString tempStr1; 121 | QString tempStr; 122 | for (register int i = 0; i < sum; i++) { 123 | if (i == left_sum - 1) { 124 | qDebug() << d1[i]; 125 | qDebug() << QString::fromStdString(s1[i]) << '='; 126 | tempStr = QString::fromStdString(s1[i]); 127 | if(d1[i] == 1) 128 | tempStr1 = QString("%2 = ").arg(tempStr); 129 | else 130 | tempStr1 = QString("%1%2 = ").arg(d1[i]).arg(tempStr); 131 | } 132 | else if (i == sum - 1) { 133 | qDebug() << d1[i]; 134 | qDebug() << QString::fromStdString(s1[i]); 135 | tempStr = QString::fromStdString(s1[i]); 136 | if(d1[i] == 1) 137 | tempStr1 = QString("%2").arg(tempStr); 138 | else 139 | tempStr1 = QString("%1%2").arg(d1[i]).arg(tempStr); 140 | } 141 | else { 142 | qDebug() << d1[i]; 143 | qDebug() << QString::fromStdString(s1[i]) << '+'; 144 | tempStr = QString::fromStdString(s1[i]); 145 | if(d1[i] == 1) 146 | tempStr1 = QString("%2 + ").arg(tempStr); 147 | else 148 | tempStr1 = QString("%1%2 + ").arg(d1[i]).arg(tempStr); 149 | } 150 | rslt += tempStr1; 151 | 152 | } 153 | qDebug() << rslt; 154 | return rslt; 155 | } 156 | else{ 157 | qDebug() << "已配平!" << "endl"; 158 | return QString("已配平!"); 159 | } 160 | } 161 | else { 162 | qDebug() << "ERROR: 无法求解!" << endl; 163 | return QString("ERROR: 无法求解!"); 164 | } 165 | } 166 | void MainWindow::InitElem() { 167 | for (register int i = 0; i < s.length(); i++) 168 | if (s[i] == '=') { 169 | iloc = i; 170 | break; 171 | } 172 | int head = 0, count = -1; 173 | for (register int i = 0; i < s.length(); i++) { 174 | if (s[i] == '+' && s[i + 1] != '>') { 175 | if (i < iloc)left_sum++; 176 | else right_sum++; 177 | count += 1; 178 | s1[count] = s.substr(head, i - head); 179 | head = i + 1; 180 | } 181 | if (i == iloc) { //读到等号 182 | count += 1; 183 | s1[count] = s.substr(head, i - head); 184 | head = i + 1; 185 | 186 | } 187 | if (i == s.length() - 1) { //最后一个 188 | count += 1; 189 | s1[count] = s.substr(head, i + 1 - head); 190 | } 191 | } 192 | left_sum++, right_sum++; 193 | sum = left_sum + right_sum; 194 | //上述将化学式分为左式和右式,并将每一个反应物和生成物切片。s1[0,left_sum-1]为左式,s1[left_sum,sum-1]为右式 195 | } 196 | inline int MainWindow::gcd(int a, int b) { 197 | return b == 0 ? a : gcd(b, a % b); 198 | } 199 | void MainWindow::ReadElem() { //读取所有的物质 200 | for (register int i = 0; i < iloc; i++) { //因为原子守恒所以只读取左边的 201 | string temp = ""; 202 | if (isupper(s[i])) { 203 | if (islower(s[i + 1])) { 204 | temp = string("") + char(s[i]) + char(s[i + 1]); 205 | } 206 | else 207 | temp = string("") + char(s[i]); 208 | elem[temp] = 0; 209 | } 210 | else if (s[i] == '<') 211 | elem["e"] = 0; 212 | } 213 | } 214 | inline int MainWindow::E_GetInt(string temp, int pos) { 215 | pos++; int x = 0; 216 | if (isdigit(temp[pos])) { 217 | while (isdigit(temp[pos])) { 218 | x = (x << 1) + (x << 3) + int(char(temp[pos]) - '0'); 219 | pos++; 220 | } 221 | } 222 | else x = 1; 223 | if (temp[pos] == '+') return x; 224 | else return ~(x - 1); 225 | } 226 | int MainWindow::check(int i) { //判断正负 227 | return i < left_sum ? 1 : -1; 228 | } 229 | string MainWindow::check1(int k) { //判断系数是否为1 230 | return k == 1 ? "" : to_string(k); 231 | } 232 | inline int MainWindow::GetInt(string temp, int pos) { //读数 233 | pos++; 234 | if (islower(temp[pos]))pos++; //小写 235 | if (!isdigit(temp[pos]))return 1; //非数字就是1 236 | else { 237 | int x = 0; 238 | while (isdigit(temp[pos])) { //读元素后面的数字 239 | x = (x << 1) + (x << 3) + int(char(temp[pos]) - '0'); 240 | pos++; 241 | } 242 | return x; 243 | } 244 | } 245 | void MainWindow::ToMatr() { 246 | for (register int i = 0; i < sum; i++) { //遍历每一个反应(生成)物 247 | for (iter = elem.begin(); iter != elem.end(); iter++) 248 | iter->second = 0; //初始化map 249 | string temp = s1[i]; //临时存贮 250 | int k1 = 1, k2 = 1; //分别代表()后的数字,[]后的数字。 251 | for (register int j = 0; j < temp.length(); j++) { 252 | if (temp[j] == '(') { 253 | int m = j + 1; 254 | while (temp[m] != ')')m++; 255 | k1 = GetInt(temp, m); 256 | } 257 | if (temp[j] == ')')k1 = 1; 258 | if (temp[j] == '[') { 259 | int m = j + 1; 260 | while (temp[m] != ']')m++; 261 | k2 = GetInt(temp, m); 262 | } 263 | if (temp[j] == ']')k2 = 1; 264 | if (isupper(temp[j])) { 265 | if (islower(temp[j + 1])) { 266 | string temp1 = string("") + char(temp[j]) + char(temp[j + 1]); 267 | elem[temp1] += GetInt(temp, j) * k1 * k2 * check(i); 268 | } 269 | else { 270 | string temp1 = string("") + char(temp[j]); 271 | elem[temp1] += GetInt(temp, j) * k1 * k2 * check(i); 272 | } 273 | } 274 | else if (temp[j] == '<') 275 | elem["e"] = E_GetInt(temp, j) * check(i); 276 | } 277 | iter = elem.begin(); 278 | int x = 0; 279 | while (iter != elem.end()) { 280 | ma[x][i] = iter->second; 281 | x++; 282 | iter++; 283 | } 284 | } 285 | } 286 | int MainWindow::determinant(int n) { 287 | int ans = 1, v = 1; 288 | for (int i = 0; i < n; i++) //列 289 | for (int j = i + 1; j < n; j++) { //行 290 | while (ma1[i][i]) { //辗转相除消元 291 | int x = ma1[j][i] / ma1[i][i]; 292 | for (int k = i; k < n; k++) //转换成下三角行列式 293 | ma1[j][k] -= x * ma1[i][k]; 294 | swap(ma1[i], ma1[j]), v = -v; //性质 4 295 | } 296 | swap(ma1[i], ma1[j]), v = -v; 297 | } 298 | for (int i = 0; i < n; i++) 299 | ans *= ma1[i][i]; //对角线求值 300 | return ans * v; 301 | } 302 | void MainWindow::solve() { 303 | flag = 1; 304 | int ele = elem.size(); 305 | for (register int i = 0; i < ele; i++) //默认最后一个生成物系数为1 306 | ma[i][sum - 1] *= -1; 307 | for (int i = 0; i < sum - 1; i++) //列 308 | for (int j = i + 1; j < ele; j++) { //行 309 | while (ma[i][i]) { 310 | int x = ma[j][i] / ma[i][i]; 311 | for (int k = i; k < sum; k++) 312 | ma[j][k] -= x * ma[i][k]; 313 | swap(ma[i], ma[j]); 314 | } 315 | swap(ma[i], ma[j]); 316 | } 317 | if (sum - ele >= 2) { 318 | flag = 0; 319 | return; 320 | } 321 | else { 322 | ele = min(ele, sum - 1); 323 | for (register int i = 0; i < ele; i++) 324 | for (register int j = 0; j < ele; j++) 325 | ma1[i][j] = ma[i][j]; 326 | D = determinant(ele); //求行列式 327 | for (register int i = 0; i < ele; i++) { //分别对sum-1个行列式求值 328 | for (register int j = 0; j < ele; j++) //行 329 | for (register int k = 0; k < ele; k++) {//列 330 | if (k == i) ma1[j][k] = ma[j][ele]; 331 | else ma1[j][k] = ma[j][k]; 332 | } 333 | d1[i] = determinant(ele); 334 | } 335 | d1[sum - 1] = D; 336 | int Gcd = d1[0]; 337 | for (register int i = 1; i < sum; i++) 338 | Gcd = gcd(Gcd, d1[i]); 339 | if (Gcd == 0) { 340 | flag = 0; 341 | return; 342 | } 343 | for (register int i = 0; i < sum; i++) { 344 | d1[i] /= Gcd; 345 | if (d1[i] <= 0) { 346 | flag = 0; 347 | return; 348 | } 349 | } 350 | } 351 | } 352 | void MainWindow::InitAll() { 353 | s = ""; 354 | elem.clear(); 355 | left_sum = right_sum = iloc = D = 0; 356 | for (register int i = 0; i < N; i++) { 357 | d1[i] = 0; 358 | d2[i] = 1; 359 | s1[i] = ""; 360 | for (register int j = 0; j < N; j++) 361 | ma1[i][j] = ma[i][j] = 0; 362 | } 363 | } 364 | string MainWindow::DelSpace(string s) { 365 | string ans = ""; 366 | for (register int i = 0; i < s.length(); i++) { 367 | if (char(s[i]) != ' ') 368 | ans.push_back(char(s[i])); 369 | } 370 | return ans; 371 | } 372 | 373 | void MainWindow::on_pushButton_3_clicked() 374 | { 375 | form->close(); 376 | close(); 377 | 378 | } 379 | 380 | 381 | void MainWindow::on_pushButton_clicked() 382 | { 383 | showMinimized(); 384 | } 385 | 386 | 387 | void MainWindow::on_pushButton_2_clicked() 388 | { 389 | form->show(); 390 | } 391 | 392 | 393 | void MainWindow::on_pushButton_4_clicked() 394 | { 395 | ui->leInput->clear(); 396 | ui->leOutput->clear(); 397 | } 398 | 399 | -------------------------------------------------------------------------------- /Graphical source code/mainwindow.h: -------------------------------------------------------------------------------- 1 | #ifndef MAINWINDOW_H 2 | #define MAINWINDOW_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include "form.h" 9 | 10 | QT_BEGIN_NAMESPACE 11 | namespace Ui { class MainWindow; } 12 | using namespace std; 13 | QT_END_NAMESPACE 14 | #define N 100 15 | 16 | 17 | class MainWindow : public QMainWindow 18 | { 19 | Q_OBJECT 20 | 21 | public: 22 | MainWindow(QWidget *parent = nullptr); 23 | int d1[N], d2[N]; // d1为最终系数,d2为原方程式的系数 24 | int ma[N][N], ma1[N][N]; //ma为增广矩阵,ma1为判重矩阵 25 | map elem; //用来存放对应元素的数量 26 | map::iterator iter; //迭代器 27 | string s; 28 | string s1[N]; //用来储存每一个反应物和生成物 29 | int left_sum = 0, right_sum = 0, iloc; //分别记录反应物、生成物种类和等号的下标 30 | int sum, D; //sum=left_sum+right_sum,D为行列式的值 31 | int flag = 1; 32 | ~MainWindow(); 33 | 34 | int gcd(int a, int b); 35 | void ReadElem(); 36 | int E_GetInt(string temp, int pos); 37 | int check(int i); 38 | string check1(int k); 39 | int GetInt(string temp, int pos); 40 | void ToMatr(); 41 | int determinant(int n); 42 | void solve(); 43 | void InitAll(); 44 | string DelSpace(string s); 45 | QString rslt; 46 | void paintEvent(QPaintEvent *event); 47 | void mousePressEvent(QMouseEvent *event); 48 | void mouseMoveEvent(QMouseEvent *event); 49 | QPoint last_mouse_position_; 50 | private slots: 51 | void on_pushButton_3_clicked(); 52 | 53 | void on_pushButton_clicked(); 54 | 55 | void on_pushButton_2_clicked(); 56 | 57 | void on_pushButton_4_clicked(); 58 | 59 | private: 60 | Ui::MainWindow *ui; 61 | bool eventFilter(QObject *watched, QEvent *event); 62 | QString cal(QString old); 63 | void InitElem(); 64 | Form *form; 65 | 66 | 67 | }; 68 | #endif // MAINWINDOW_H 69 | -------------------------------------------------------------------------------- /Graphical source code/mainwindow.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | MainWindow 4 | 5 | 6 | 7 | 0 8 | 0 9 | 800 10 | 300 11 | 12 | 13 | 14 | 15 | 800 16 | 300 17 | 18 | 19 | 20 | 21 | 800 22 | 300 23 | 24 | 25 | 26 | Chemical Balancer 27 | 28 | 29 | 30 | :/img/icon.ico:/img/icon.ico 31 | 32 | 33 | 1.000000000000000 34 | 35 | 36 | false 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 110 49 | 130 50 | 641 51 | 41 52 | 53 | 54 | 55 | 56 | 12 57 | 58 | 59 | 60 | 61 | 62 | 63 | 110 64 | 190 65 | 641 66 | 41 67 | 68 | 69 | 70 | 71 | 12 72 | 73 | 74 | 75 | true 76 | 77 | 78 | 79 | 80 | 81 | 20 82 | 140 83 | 91 84 | 21 85 | 86 | 87 | 88 | 89 | 12 90 | 91 | 92 | 93 | 化学方程: 94 | 95 | 96 | 97 | 98 | 99 | 20 100 | 200 101 | 91 102 | 21 103 | 104 | 105 | 106 | 107 | 12 108 | 109 | 110 | 111 | 配平结果: 112 | 113 | 114 | 115 | 116 | 117 | 630 118 | 260 119 | 141 120 | 20 121 | 122 | 123 | 124 | 125 | 12 126 | 127 | 128 | 129 | Powerd by:AMT 130 | 131 | 132 | 133 | 134 | 135 | 340 136 | 10 137 | 121 138 | 121 139 | 140 | 141 | 142 | 143 | 12 144 | 145 | 146 | 147 | image: url(:/img/1.jpeg); 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 690 157 | 10 158 | 50 159 | 46 160 | 161 | 162 | 163 | 164 | 50 165 | 50 166 | 167 | 168 | 169 | 170 | 22 171 | 172 | 173 | 174 | image: url(:/img/3.jpg); 175 | 176 | 177 | 178 | 179 | 180 | 181 | 182 | 183 | 640 184 | 10 185 | 50 186 | 46 187 | 188 | 189 | 190 | 191 | 50 192 | 50 193 | 194 | 195 | 196 | 197 | 22 198 | 199 | 200 | 201 | image: url(:/img/1.jpg); 202 | 203 | 204 | 205 | 206 | 207 | 208 | 209 | true 210 | 211 | 212 | 213 | 740 214 | 10 215 | 50 216 | 46 217 | 218 | 219 | 220 | 221 | 0 222 | 0 223 | 224 | 225 | 226 | 227 | 50 228 | 50 229 | 230 | 231 | 232 | 233 | 22 234 | 235 | 236 | 237 | image: url(:/img/2.jpg); 238 | 239 | 240 | 241 | 242 | 243 | 244 | 245 | 246 | 247 | :/img/yjtp (1).ico:/img/yjtp (1).ico 248 | 249 | 250 | 帮助 251 | 252 | 253 | 254 | 255 | 256 | 257 | 258 | 259 | -------------------------------------------------------------------------------- /Graphical source code/res.qrc: -------------------------------------------------------------------------------- 1 | 2 | 3 | yjtp (1).ico 4 | style.qss 5 | 2.jpg 6 | 3.jpg 7 | 1.jpg 8 | 1.jpeg 9 | icon.ico 10 | 11 | 12 | -------------------------------------------------------------------------------- /Graphical source code/style.qss: -------------------------------------------------------------------------------- 1 | QPushButton 2 | { 3 | background-color:transparent;; 4 | } 5 | -------------------------------------------------------------------------------- /Graphical source code/yjtp (1).ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AMT-J/Chemical-Balancer/bdff545006108a02709a6a5e9c44b7a8932c28d5/Graphical source code/yjtp (1).ico -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2022 AMT 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README-cn.md: -------------------------------------------------------------------------------- 1 |

化学配平器

2 |

3 | English | 4 | 中文 5 |

6 |

7 | 8 | 9 | 10 | 11 | 12 |

13 | 14 |

15 | 16 | 17 |

18 | 19 | ## 简介 20 | 21 | - 本程序可实现化学、离子方程式的配平和检测是否配平 22 | - 输入的化学方程式规则如下: 23 | 24 | ``` 25 | ::= "=" 26 | ::= | "+" 27 | ::= | "" | 28 | ::= "<""+>" | "<""->" | "" 29 | ::= {} 30 | ::= "0" | "1" | ... | "9" 31 | ::= | 32 | ::= | "(" ")" | "[" "]" 33 | ::= | 34 | ::= "A" | "B" | ... | "Z" 35 | ::= "a" | "b" | ... | "z" 36 | ``` 37 | ## 应用 38 | - [下载](https://github.com/AMT-J/Chemical-Balancer/releases/tag/v1.0) 39 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 |

Chemical Balancer

2 |

3 | English | 4 | 中文 5 |

6 |

7 | 8 | 9 | 10 | 11 | 12 |

13 | 14 |

15 | 16 | 17 |

18 | 19 | ## Introduction 20 | 21 | - This program can realize the balance of chemical and ionic equations and check whether they are balanced 22 | - The rules for entering chemical equations are as follows: 23 | 24 | ``` 25 | ::= "=" 26 | ::= | "+" 27 | ::= | "" | 28 | ::= "<""+>" | "<""->" | "" 29 | ::= {} 30 | ::= "0" | "1" | ... | "9" 31 | ::= | 32 | ::= | "(" ")" | "[" "]" 33 | ::= | 34 | ::= "A" | "B" | ... | "Z" 35 | ::= "a" | "b" | ... | "z" 36 | ``` 37 | ## Apply 38 | - [Download](https://github.com/AMT-J/Chemical-Balancer/releases/tag/v1.0) 39 | --------------------------------------------------------------------------------