Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "mainwindow.h"
- #include "ui_mainwindow.h"
- #include <QDebug>
- #include <QElapsedTimer>
- MainWindow::MainWindow(QWidget *parent)
- : QMainWindow(parent)
- , ui(new Ui::MainWindow){
- ui->setupUi(this);
- }
- MainWindow::~MainWindow(){
- delete ui;
- }
- void MainWindow::on_pushButton_clicked(){
- QElapsedTimer timer;
- int solutions = 0;
- qint64 before, after;
- timer.start();
- for(int u=1; u<=9 ;u++){
- for(int q=0; q<=9; q++){
- for(int a=1; a<=9; a++){
- for(int p=0; p<=9; p++){
- if(u==q || u==a || u==p || q==a || q==p || a==p){
- continue;
- }
- int uqq = u*100 + q*10 + q;
- int aqqp = a*1000 + q*100 + q*10 + p;
- if(4*uqq == aqqp){
- solutions++;
- }
- }
- }
- }
- }
- before = timer.nsecsElapsed();
- ui->stupidLabel->setText("Stupid Method : " + QString::number(before) + " ns, " + QString::number(solutions) + " solutions(s)");
- solutions = 0;
- timer.start();
- for(int u=1; u<=9 ;u++){
- if(u*4 < 10){
- continue;
- }
- for(int q=0; q<=9; q++){
- if(u==q || (u*4)%10 != (q*4)%10){
- continue;
- }
- for(int p=1; p<=9; p++){
- if((q*4)%10 != p || u==p || q==p || (q*4)/10 + (q*4)%10 != q){
- continue;
- }
- for(int a=1; a<=3; a++){
- if((u*4)/10 != a){
- continue;
- }
- if(u==a || q==a|| p==a){
- continue;
- }
- int uqq = u*100 + q*10 + q;
- int aqqp = a*1000 + q*100 + q*10 + p;
- if(4*uqq == aqqp){
- solutions++;
- }
- }
- }
- }
- }
- after = timer.nsecsElapsed();
- ui->improvedLabel->setText("Improved Method : " + QString::number(after) + " ns, " + QString::number(solutions) + " solutions(s)");
- ui->compLabel->setText("Efficiency Comparation : " + QString::number((double)after/before*100) + "%");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement