1205 Word flipping

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.