Advertisement
Guest User

Untitled

a guest
Oct 26th, 2019
327
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.16 KB | None | 0 0
  1. #include <iostream>
  2. #include <sstream>
  3. #include <string>
  4. #include <time.h>
  5. #include <stdlib.h>
  6. #include <stdio.h>
  7. #include <vector>
  8. #include <algorithm>
  9.  
  10. using namespace std;
  11.  
  12.  
  13. class Sentance
  14. {
  15. private:
  16.  
  17. string words;
  18.  
  19. vector<string> toVector ()
  20. {
  21. istringstream istr(words);
  22. string temp;
  23.  
  24. vector<string> tempVec;
  25.  
  26. while(istr>>temp)
  27. {
  28. tempVec.push_back(temp);
  29.  
  30. }
  31.  
  32. return tempVec;
  33. }
  34. vector<string>sentanceVec=toVector();
  35. int SIZE=sentanceVec.size();
  36.  
  37.  
  38. public:
  39. Sentance(string& str):
  40. words(str){}
  41. Sentance()
  42. {
  43. words="not initiallized";
  44. }
  45.  
  46.  
  47.  
  48. getRandomized(Sentance& s)
  49. {
  50. // for(string a : sentanceVec)
  51. // {
  52. // cout<< a << " ";
  53. // }
  54.  
  55. vector<int> checkVec;
  56. bool flag=false;
  57.  
  58. for(int a=0; a<SIZE-1; ++a)
  59. {
  60. int switcher=rand()%SIZE;
  61. if(a==0)
  62. {
  63. checkVec.push_back(switcher);
  64. }else
  65. {
  66. for(int b=0; b<=checkVec.size()-1; ++b)
  67. {
  68. if(switcher==checkVec[b])
  69. {
  70. flag=false;
  71. break;
  72. }else
  73. {
  74. flag=true;
  75. }
  76. }
  77. if(flag==true)
  78. {
  79. checkVec.push_back(switcher);
  80. flag=false;
  81. }
  82. }
  83. }
  84.  
  85. for(int a=0; a<SIZE-1; ++a)
  86. {
  87. if(checkVec[a]==a)
  88. {
  89. continue;
  90. }else if (a<=checkVec.size()-1)
  91. {
  92. iter_swap(sentanceVec.begin()+a,
  93. sentanceVec.begin()+checkVec[a]);
  94. }
  95. }
  96.  
  97. for(string a : sentanceVec)
  98. {
  99. cout<< a << endl;
  100. }
  101.  
  102. }
  103.  
  104. };
  105.  
  106.  
  107.  
  108. main(){
  109.  
  110. srand(time(NULL));
  111. string str;
  112. getline(cin, str);
  113.  
  114. Sentance first(str);
  115. first.getRandomized(first);
  116.  
  117.  
  118. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement