Help please...
Feb 16, 2017 at 9:36am UTC
Hello friends, I'm not good enough on C++.. but I'm trying my best to do what is possible for me.
I want you to help me On random words... I want an random which can random words like this..
1. Friends - family - others
2. Friends - others - family
3. Family - friends - others
4. Others - friends - family
5. Others - family - friends
6.
And even end without repeating a sentence.
Here is my codes that I've tryied.
http://pastebin.com/ZG0MmXb8
YOU CAN SEE AN EXAMPLE OF IMAGE HERE..
https://drive.google.com/open?id=0B7nVIx-BAIdrdmdTVUJRQkVJT0k
Feb 16, 2017 at 9:51am UTC
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
int main()
{
int i;
const int SIZE = 3;
std::string strings[SIZE] = {"Friends" , "family" , "others" };
std::sort(strings, &strings[SIZE]);
int k = 1;
do
{
std::cout << k << ". " ;
for (i = 0; i < SIZE; i++)
{
std::cout << strings[i];
if (i < SIZE - 1) std::cout << " - " ;
}
k++;
std::cout << std::endl;
} while (std::next_permutation(strings, &strings[SIZE]));
return 0;
}
You use
std::next_permutation to complete this task.
http://www.cplusplus.com/reference/algorithm/next_permutation/
1. Friends - family - others
2. Friends - others - family
3. family - Friends - others
4. family - others - Friends
5. others - Friends - family
6. others - family - Friends
Feb 16, 2017 at 1:23pm UTC
Thank you so much, It's working Great...
Topic archived. No new replies allowed.