Well, I bumped into an interesting C++ problem last night while I was aimlessly surfing the Internet, and, of course, it caught my attention. It said something like this:
"From a file it's read a text that contains a phrase, on a line. The program rearranges the letters in each phrase, in alphabetical order, keeping the words' place. only letters from 'A' to 'Z' are affected. The other chars remain untouched. Print on the screen the result."
Too bad I don't remember the link, but I'm sure this was the requirement.
It looked quite simple, but, what I got from my ideas was..uhh NULL...
I thought I could find the number of words and then somehow, using Bubble sort, to put them in alphabetical order. Of course, I got nothing but a broken mind :|
If you have any ideas, I'd like to know how this thing it's solved :)
PS: I'm posting what I tried to make by myself, too :P
#include <iostream.h>
#include <string.h>
int main ()
{
char text[100];
int i, ok;
cout<<"text ";
cin.get (text, 100);
do
{
ok=0;
for (i=0; i<strlen (text )-1; i++)
if (text[i] > text[i+1])
{
char x=text[i];
text[i]=text[i+1];
text[i]=x;
ok=1;
}
}
while (ok==1);
for (i=0; i<strlen (text); i++)
cout<<text[i]<<" ";
cout<<endl;
return 0;
}