jeudi 13 août 2015

Script for multiplying by 2 and checking for digits

I am trying to make a script with C++ that multiplies permutations of 123567890 (no 4) by 2, and checks if the number is a permutation of 1234567890. I have made a script, but it doesn't work. Please check the script and tell me how to fix it.

#include <iostream>
#include <sstream>
#include <algorithm>
#include <vector>
#include <random>
#include <chrono>
using namespace std;


int main() {
    int myints[] = { 5, 6, 7, 8, 9, 0, 1, 2, 3 };
    int two[] = { 1, 2, 3, 5, 6, 7, 8, 9, 0 };
    int num = 1;
    string numString;
    int numList[] = { 0 };
    int counter = 0;
    int mult = 0;
    int zero = 0;
    string numTemp;

    do {
        stringstream buffer;
        buffer << myints[0] << ' ' << myints[1] << ' ' << myints[2] << ' ' << myints[3] << ' ' << myints[4] << ' ' << myints[5] << ' ' << myints[6] << ' ' << myints[7] << ' ' << myints[8] << '\n';
        cout << buffer.str();

        numString = buffer.str();
        num = stoi(numString);

        if (zero = num % 2) {
            do {
                numList[counter] = (num / (10 ^ counter) % 10);
                counter += 1;
            } while (counter != 9);
            do {
                num *= 2;
                mult += 1;
                numTemp = to_string(num);
                if (numTemp.find(1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & 9 & 10 != std::string::npos)) {
                    cout << "Success" << ' ' << num << " x2^" << mult;
                    return 0;
                }
            } while (num < 10000000000);
        }

    } while (std::next_permutation(myints, myints + 9));

    return 0;
}

Thank you for your assistance



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire