Hi! I wanna write a program that changes the places of the words of a sentence recursively. suppose that the input is :
**I****am*fine**.**How*are*you***.******* (the asterisks represent spaces)
then the output must be :
**you****are*How**.**fine*am*I***.*******
but note that the number and the places of spaces are the same as they used to be(only the places of the words have changed). there should be no additional strings other than the main one that stores the input data; which means whatever is done shoud be done on the main string.
I have come up with the idea of a program that returns the words just like what mentioned but I don't know what to do with the spaces.
my program is:
Code:
string s;
void f()
{
cin>>s;
if(s==".")
return;
f();
cout<<s;
}
the problem is that "cin" doesn't get spaces. I'd appreciate it if you help me.
thanks