Problem Description:
Write a function to convert I am a student to student a am I
Problem Solving Ideas:
I am a student--->--> student a am i#include<iostream>using namespace std;/* Flip Function---> Take advantage of Exchange */void Words_re Verse (char str[],int left,int right) {when (left < right) {Str[left] + = str[right];str[right] = str[left]-str[right];s Tr[left]-= str[right];left++;right--;}} int main () {char str[] = "Student a Am I";/* finds the array (leftmost) and (rightmost) after the overall rollover */int left = 0;int right = 0;while (Str[right]! = ' + ') {RI ght++;} Words_reverse (str,left,right-1);/* Find each word (leftmost) and (rightmost), flip each word */int lowflag = 0; Status flag bit: The left side of the string to invert is found int highflag = 0;//status flag bit: the right side of the string to invert is found int i = 0;while (str[i]! = ')} {/* Search for the leftmost, low */if of the word (Str[i]! = "&& Lowflag = = 0)//If no word is found on the leftmost premise, if a non-empty characters is found to indicate the leftmost side found {Lowflag = 1;left = i;} /*if (str[i] = = "&& Highflag = = 0)//char str[] =" I am a student "situation is not appropriate (the last side has a space) {Highflag = 1;right = i-1;} *//* search for the right and low */if of the word (Lowflag = = 1 && str[i] = = ' && highflag = 0)//char str[] = "Student a Am I"; A word does not flip) {Highflag = 1;//without finding the right side of the word, if a space character is found, the first word is the mostRight-hand character = i-1;} /* Leftmost (low) and rightmost (high) are found after completing the flip */if (Lowflag = = 1 && highflag = = 1) {words_reverse (str,left,right); lowflag = 0; Highflag = 0;} i++;} Cout<<str<<endl;return 0;}
Word Flip (I am a student)--->> (Student a Am I)