Topic:
Flip all the words in the sentence, the word content is unchanged, for example
I ' m a student. ---->student. A I ' am
Ideas:
This is the same idea as looping or flipping the previous array.
1. Each word is flipped individually, such as M ' I a. tneduts
2, flip the whole sentence, such as student. A I ' m
Since this is all flipped, it is the same as the effect of flipping it first, then flipping it all over and flipping it over and over and over in a single flip.
Code:
#include <iostream>using namespacestd;voidReversestring&STR,intStartintend) { Chartmp; intI=start; intj=end; while(i<j) {tmp=Str[i]; Str[i]=Str[j]; STR[J]=tmp; I++; J--; }}voidReverse_sentence (string&str) { intlen=str.length (); intstart=0; intindex=0; while(index<Len) { while(str[index]!=' '&& index<len) Index++; Reverse (Str,start,index-1); while(str[index]==' '&& index<len) Index++; Start=index; } reverse (str,0, len-1);}intMain () {stringStr="I ' m a student!";//cout<<str.length () <<endl;// the//cout<<sizeof (str) <<endl; //4reverse_sentence (str); cout<<str<<Endl; return 0;}
Operation Result:
(string) sentence flipping