Archived

This topic is now archived and is closed to further replies.

Austrian Coder

Random order

Recommended Posts

Split it up into four strings and randomly merge them together into a new one.


____________________ ____ ___ __ _
Enselic's Corner - My site. Go test my game Spatra and see if you can beat it onto the Official Spatra Top 10.

CodeSampler.com - Great site with source for specific tasks in DirectX and OpenGL.

[edited by - Enselic on May 3, 2003 10:01:11 AM]

Share this post


Link to post
Share on other sites
I''ve never coded with the std::string but:

for n pairs
string n = base_string( char n * 3 to char n * 3 + 2 )



____________________ ____ ___ __ _
Enselic''s Corner - My site. Go test my game Spatra and see if you can beat it onto the Official Spatra Top 10.
CodeSampler.com - Great site with source for specific tasks in DirectX and OpenGL.

Share this post


Link to post
Share on other sites
edit: in the joy of creation, I didn't think this could be a homework question. Solution removed.

Hint: use stringstream to split the string into smaller strings (it splits on whitespace)

[edited by - civguy on May 3, 2003 10:29:05 AM]

Share this post


Link to post
Share on other sites
Well, I hope this helps then:

      
int main() {
using namespace std;

string input = "1A 2B 3C 4D";
stringstream ss(input);
vector<string> tokens;
while (ss.good()) {
string text;
ss >> text;
tokens.push_back(text);
}
random_shuffle(tokens.begin(), tokens.end());
stringstream result_ss;
copy(tokens.begin(), tokens.end(), ostream_iterator<string>(result_ss, " "));
string output = result_ss.str();
}
(untested)

Share this post


Link to post
Share on other sites