Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "pch.h"
- #include <iostream>
- #include <string>
- #include <algorithm>
- #include <ctime>
- #include <omp.h>
- using namespace std;
- int sum, a, b, c, ld, lj, poLewej = 4, licz = 0, licz_operacje = 0;
- string aS, bS, cS, liczba;
- int main()
- {
- string s("0123456789");
- double start = omp_get_wtime();
- for (int i = 0; i < 99; i++)
- {
- c = 98 - i;
- if (c > 9 && c % 11 != 0)
- {
- liczba = to_string(c);
- ld = (liczba.at(0)) - '0';
- lj = (liczba.at(1)) - '0';
- if (ld > lj)
- {
- s.erase(ld, 1);
- s.erase(lj, 1);
- }
- else
- {
- s.erase(lj, 1);
- s.erase(ld, 1);
- }
- }
- else if (c % 11 != 0)
- {
- s.erase(c, 1);
- poLewej = 5;
- }
- else
- continue;
- //cout << endl << s << " Petla nr. " << i << endl << endl;
- for (int k = 1; k < 3; k++) // Pętla w celu, gdy k = 2, usuwa 0 i dodaje do "c"
- {
- if (k == 2)
- {
- if (c % 10 == 0)
- continue;
- s.erase(0, 1);
- cS = "0" + to_string(c);
- poLewej = 4;
- }
- else
- cS = to_string(c);
- do {
- #pragma omp parallel for schedule(dynamic, 4) num_threads(8)
- for (int j = poLewej; j < s.length(); j++)
- {
- b = stoi(s.substr(j, s.length()));
- if (b != 0)
- {
- a = stoi(s.substr(0, j));
- if ((a > b) && (a%b == 0))
- {
- sum = 0;
- sum = (a / b) + c;
- if (sum == 100)
- {
- cout << s.substr(0, j) << " / " << s.substr(j, s.length()) << " + " << cS << " = " << "100" << endl;
- cout << "Watek: " << omp_get_thread_num() << endl;
- licz++;
- }
- }
- }
- }
- licz_operacje++;
- } while (next_permutation(s.begin(), s.end()));
- if (k == 2)
- {
- s.insert(0, "0");
- }
- }
- if (c > 9)
- {
- if (ld < lj)
- {
- s.insert(ld, to_string(ld));
- s.insert(lj, to_string(lj));
- }
- else
- {
- s.insert(lj, to_string(lj));
- s.insert(ld, to_string(ld));
- }
- }
- else
- s.insert(c, to_string(c));
- }
- double stop = omp_get_wtime();
- cout << "Czas wykonania: " << (stop - start) << endl;
- cout << "Operacje: " << licz_operacje << endl;
- cout << "Result: " << licz;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement