Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <omp.h>
- #include <iostream>
- #include <string>
- #include <vector>
- #include <math.h>
- using namespace std;
- void work(int thread_num, int len, string str, vector<string> other, int& pos, int& length) {
- int a = omp_get_thread_num();
- int start = len * a;
- //cout << a << endl;
- for (int i = start; i < start + len - 1; i++) {
- for (int j = 1; j < str.length() - i + 1; j++) {
- string check = str.substr(i, j);
- bool found = true;
- for (int i = 0; i < other.size(); i++) {
- if (other[i].find(check) == -1)
- found = false;
- }
- if (found == true)
- if (check.length() > length)
- #pragma omp critical
- {
- pos = i;
- length = j;
- }
- }
- }
- }
- int factorial(int n)
- {
- return (n == 1 || n == 0) ? 1 : factorial(n - 1) * n;
- }
- int main(int argc, char** argv[]) {
- int thread_num = 2;
- omp_set_num_threads(thread_num);
- string str = "aatyuioddd";
- int count = 0;
- for (int i = 1; i <= str.length(); i++) {
- count += factorial(i);
- }
- cout << count << endl;
- vector<string> strings;
- strings.push_back("aaaaaaaaaaaaaaaaaaaaaaaddddddddddddddddd");
- strings.push_back("aaaaaaaaaaaaaaaaaaaaaaaaaddddddddddddd");
- //cout << strings.size() << endl;
- int pos = 0, length = 0;
- #pragma omp parallel
- work(thread_num, str.length() / thread_num, str, strings, pos, length);
- cout << str.substr(pos, length) << endl;
- //cout << "Max substring: " << max_substring << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement