Title Description
Description
Give an English sentence, I hope you turn over the word order in the sentence
Enter a description
Input Description
The input includes an English sentence.
Output description
Output Description
Reverse the word output in the order of the words
Sample input
Sample Input
I Love You
Sample output
Sample Output
Love I
Idea: The sentence is stored in a string in the array, separated by a space word. Start with the last space to output a word
#include <stdio.h>
#include <string.h>
int main ()
{
Char s[1000];
int index[100],i,j=0,len,l;
Gets (s);//Get English sentences
Len=strlen (s);//Sentence length
for (i=0;i<len;i++)//Find out the index position of all spaces
{
if (s[i]== ")
{
Index[j++]=i;
}
}
for (i=j-1;i>=0;i--)//from the left after a space to start the backward output "word", the last word encountered a character array
Terminator end, middle word encountered after the end of the space, notice here missing the first word
{
for (l=index[i]+1;l<len;l++)
{
if (s[l]== ")
{
Break
}
printf ("%c", S[l]);
}
printf ("");
}
Outputs the first word and wraps the last letter.
for (l=index[0]-1;l>0;l--)
{
printf ("%c", S[l]);
}
printf ("%c\n", S[l]);
return 0;
}
1205 Word flipping