Advertisement
Guest User

OR

a guest
Jan 21st, 2020
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.47 KB | None | 0 0
  1. #include "pch.h"
  2. #include <iostream>
  3. #include <string>
  4. #include <algorithm>
  5. #include <ctime>
  6. #include <omp.h>
  7. #include <vector>
  8.  
  9.  
  10. using namespace std;
  11. string firstStr, secondStr, thirdStr, getPermutation;
  12. int firstInt, secondInt, thirdInt, choose, k;
  13. int licz = 0;
  14. vector<string> readOut;
  15.  
  16. void sequency()
  17. {
  18. string s("0123456789");
  19. vector<string> tab;
  20.  
  21. cout << endl << "Rozpoczeto generowanie permutacji... ";
  22.  
  23. clock_t start = clock();
  24.  
  25. do {
  26. tab.push_back(s);
  27. } while (next_permutation(s.begin(), s.end()));
  28.  
  29. cout << " OK " << endl;
  30.  
  31. for (int k = 0; k < tab.size(); k++) {
  32. getPermutation = tab[k];
  33. for (int leftSide = 1; leftSide < getPermutation.length() - 1; leftSide++) {
  34. for (int rightSide = (getPermutation.length() - 1); rightSide > leftSide; rightSide--) {
  35. firstStr = getPermutation.substr(0, leftSide);
  36. firstInt = stoi(firstStr);
  37.  
  38. secondStr = getPermutation.substr(leftSide, (rightSide - leftSide));
  39. secondInt = stoi(secondStr);
  40.  
  41. thirdStr = getPermutation.substr(rightSide, (getPermutation.length() -rightSide));
  42. thirdInt = stoi(thirdStr);
  43.  
  44. if (secondInt != 0 && (firstInt%secondInt == 0) && ((firstInt / secondInt) + thirdInt == 100))
  45. {
  46. readOut.push_back(firstStr + " / " + secondStr + " + " + thirdStr + " = 100");
  47. licz++;
  48. cout << licz << endl;
  49. }
  50. if (thirdInt != 0 && (secondInt%thirdInt == 0) && (firstInt + (secondInt / thirdInt) == 100))
  51. {
  52. readOut.push_back(firstStr + " + " + secondStr + " / " + thirdStr + " = 100");
  53. licz++;
  54. cout << licz << endl;
  55. }
  56. }
  57. }
  58. }
  59.  
  60. clock_t stop = clock();
  61. cout << "Wygenerowano liczbe mozliwosci w liczbie: " << tab.size() << endl;
  62. cout << "Liczba znalezionych liczbe sposobow uzyskania wyniku 100: " << licz << endl;
  63. cout << "Czas realizacji: " << (stop - start) << endl;
  64. }
  65.  
  66. void menu()
  67. {
  68. system("cls");
  69. cout << "Program znajdujacy liczbe sposobow w jaki mozna wstawic operacje + i / pomiedzy cyfry 0, 1, . . ., 9 w taki sposob, aby powstale dzialanie dalo wynik rowny 100" << endl;
  70. cout << "MENU - wybierz interesujaca Cie opcje" << endl;
  71. cout << "1. Wyszukiwanie liczb w sposob sekwencyjny" << endl;
  72. cout << "2. Wyszukiwanie liczb w sposob rownoległy" << endl;
  73. cout << "Twoj wybor (zatwierdz ENTER`em): ";
  74. cin >> choose;
  75.  
  76. switch (choose)
  77. {
  78. case 1:
  79. sequency();
  80. default:
  81. cout << "Nie ma takiej opcji w MENU!" << endl;
  82. menu();
  83. }
  84. }
  85.  
  86.  
  87. int main()
  88. {
  89. omp_set_num_threads(4);
  90. menu();
  91. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement