Advertisement
Guest User

Untitled

a guest
Mar 30th, 2017
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.45 KB | None | 0 0
  1. #include <omp.h>
  2. #include <iostream>
  3. #include <string>
  4. #include <vector>
  5. #include <math.h>
  6.  
  7. using namespace std;
  8.  
  9. void work(int thread_num, int len, string str, vector<string> other, int& pos, int& length) {
  10. int a = omp_get_thread_num();
  11. int start = len * a;
  12.  
  13. //cout << a << endl;
  14. for (int i = start; i < start + len - 1; i++) {
  15. for (int j = 1; j < str.length() - i + 1; j++) {
  16. string check = str.substr(i, j);
  17.  
  18. bool found = true;
  19. for (int i = 0; i < other.size(); i++) {
  20. if (other[i].find(check) == -1)
  21. found = false;
  22. }
  23.  
  24. if (found == true)
  25. if (check.length() > length)
  26. #pragma omp critical
  27. {
  28. pos = i;
  29. length = j;
  30. }
  31. }
  32. }
  33. }
  34.  
  35. int factorial(int n)
  36. {
  37. return (n == 1 || n == 0) ? 1 : factorial(n - 1) * n;
  38. }
  39.  
  40. int main(int argc, char** argv[]) {
  41.  
  42. int thread_num = 2;
  43. omp_set_num_threads(thread_num);
  44.  
  45. string str = "aatyuioddd";
  46.  
  47. int count = 0;
  48. for (int i = 1; i <= str.length(); i++) {
  49. count += factorial(i);
  50. }
  51.  
  52. cout << count << endl;
  53.  
  54. vector<string> strings;
  55. strings.push_back("aaaaaaaaaaaaaaaaaaaaaaaddddddddddddddddd");
  56. strings.push_back("aaaaaaaaaaaaaaaaaaaaaaaaaddddddddddddd");
  57.  
  58. //cout << strings.size() << endl;
  59. int pos = 0, length = 0;
  60. #pragma omp parallel
  61. work(thread_num, str.length() / thread_num, str, strings, pos, length);
  62.  
  63. cout << str.substr(pos, length) << endl;
  64. //cout << "Max substring: " << max_substring << endl;
  65.  
  66. return 0;
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement