码迷,mamicode.com
首页 > 其他好文 > 详细

PAT1009. 说反话 (20)

时间:2015-01-20 13:29:06      阅读:143      评论:0      收藏:0      [点我收藏+]

标签:

给定一句英语,要求你编写程序,将句中所有单词的顺序颠倒输出。

输入格式:测试输入包含一个测试用例,在一行内给出总长度不超过80的字符串。字符串由若干单词和若干空格组成,其中单词是由英文字母(大小写有区分)组成的字符串,单词之间用1个空格分开,输入保证句子末尾没有多余的空格。

输出格式:每个测试用例的输出占一行,输出倒序后的句子。

输入样例:

Hello World Here I Come

输出样例:

Come I Here World Hello

思路:注意格式

技术分享
 1 #include <stdio.h>
 2 #include <string.h>
 3 
 4 /* run this program using the console pauser or add your own getch, system("pause") or input loop */
 5 int main(int argc, char** argv) {
 6 char temp[100];
 7 gets(temp);
 8 int length=strlen(temp);
 9 int i;
10 // printf("%s",temp);
11 for(i=length-1;i>=0;i--)
12 {
13 //printf("%s",temp);
14 if(temp[i]== ||i==0)
15 {
16 if(i==0)
17 i=-1;
18 int j;
19 for(j=i+1;temp[j]!= &&temp[j]!=\0;j++)
20 putchar(temp[j]);
21 if(i!=-1)
22 putchar( );
23 else
24 putchar(\n);
25 }
26 
27 }
28 return 0;
29 }
View Code

 

PAT1009. 说反话 (20)

标签:

原文地址:http://www.cnblogs.com/GoFly/p/4235645.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!