Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <sstream>
- #include <string>
- #include <time.h>
- #include <stdlib.h>
- #include <stdio.h>
- #include <vector>
- #include <algorithm>
- using namespace std;
- class Sentance
- {
- private:
- string words;
- vector<string> toVector ()
- {
- istringstream istr(words);
- string temp;
- vector<string> tempVec;
- while(istr>>temp)
- {
- tempVec.push_back(temp);
- }
- return tempVec;
- }
- vector<string>sentanceVec=toVector();
- int SIZE=sentanceVec.size();
- public:
- Sentance(string& str):
- words(str){}
- Sentance()
- {
- words="not initiallized";
- }
- getRandomized(Sentance& s)
- {
- // for(string a : sentanceVec)
- // {
- // cout<< a << " ";
- // }
- vector<int> checkVec;
- bool flag=false;
- for(int a=0; a<SIZE-1; ++a)
- {
- int switcher=rand()%SIZE;
- if(a==0)
- {
- checkVec.push_back(switcher);
- }else
- {
- for(int b=0; b<=checkVec.size()-1; ++b)
- {
- if(switcher==checkVec[b])
- {
- flag=false;
- break;
- }else
- {
- flag=true;
- }
- }
- if(flag==true)
- {
- checkVec.push_back(switcher);
- flag=false;
- }
- }
- }
- for(int a=0; a<SIZE-1; ++a)
- {
- if(checkVec[a]==a)
- {
- continue;
- }else if (a<=checkVec.size()-1)
- {
- iter_swap(sentanceVec.begin()+a,
- sentanceVec.begin()+checkVec[a]);
- }
- }
- for(string a : sentanceVec)
- {
- cout<< a << endl;
- }
- }
- };
- main(){
- srand(time(NULL));
- string str;
- getline(cin, str);
- Sentance first(str);
- first.getRandomized(first);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement