PAT (Basic Level) Practise (中文)- 1009. 说反话 (20)
2015-04-28 18:38
465 查看
http://www.patest.cn/contests/pat-b-practise/1009
给定一句英语,要求你编写程序,将句中所有单词的顺序颠倒输出。
输入格式:测试输入包含一个测试用例,在一行内给出总长度不超过80的字符串。字符串由若干单词和若干空格组成,其中单词是由英文字母(大小写有区分)组成的字符串,单词之间用1个空格分开,输入保证句子末尾没有多余的空格。
输出格式:每个测试用例的输出占一行,输出倒序后的句子。
输入样例:
输出样例:
给定一句英语,要求你编写程序,将句中所有单词的顺序颠倒输出。
输入格式:测试输入包含一个测试用例,在一行内给出总长度不超过80的字符串。字符串由若干单词和若干空格组成,其中单词是由英文字母(大小写有区分)组成的字符串,单词之间用1个空格分开,输入保证句子末尾没有多余的空格。
输出格式:每个测试用例的输出占一行,输出倒序后的句子。
输入样例:
Hello World Here I Come
输出样例:
Come I Here World Hello
#include<stdio.h> #include<string.h> int main() { char str[100]; gets(str); int iStart=0,iLen=0,len=strlen(str); int iStr=0; char temp='0'; for(int i=0,j=len-1;i<j;i++,j--) { temp=str[i]; str[i]=str[j]; str[j]=temp; } iStr=0; while(str[iStr]) { if(str[iStr]==' ') { if(iLen>0) for(int i=iStart,j=iStart+iLen-1;i<j;i++,j--) { temp=str[i]; str[i]=str[j]; str[j]=temp; } iStart=iStr+1; iLen=0; } else iLen++; iStr++; } if(iLen>0) for(int i=iStart,j=iStart+iLen-1;i<j;i++,j--) { temp=str[i]; str[i]=str[j]; str[j]=temp; } puts(str); return 0; }
相关文章推荐
- PAT (Basic Level) Practise (中文)1009. 说反话 (20)
- PAT (Basic Level) Practise (中文)1009. 说反话 (20)
- PAT (Basic Level) Practise (中文)1009. 说反话 (20)
- PAT (Basic Level) Practise (中文)1009. 说反话 (20)
- PAT (Basic Level) Practise (中文) 1009说反话 (20)
- PAT乙级真题及训练集 PAT (Basic Level) Practise (中文)1009. 说反话
- PAT (Basic Level) Practise (中文) 1009.说反话
- PAT (Basic Level) Practise-1009. 说反话 (20)
- PAT (Basic Level) Practise (中文)1049. 数列的片段和(20)
- PAT (Basic Level) Practise (中文) 1007素数对猜想 (20)
- PAT (Basic Level) Practise (中文) 1023. 组个最小数 (20)
- PAT (Basic Level) Practise (中文)1024. 科学计数法 (20)
- PAT (Basic Level) Practise (中文)1028. 人口普查(20)
- PAT (Basic Level) Practise (中文)1004. 成绩排名 (20)
- PAT (Basic Level) Practise (中文)1012. 数字分类 (20)
- PAT (Basic Level) Practise (中文)- 1013. 数素数 (20)
- PAT (Basic Level) Practise (中文)1042. 字符统计(20)
- PAT (Basic Level) Practise (中文) 1007. 素数对猜想 (20)
- PAT (Basic Level) Practise (中文)1014. 福尔摩斯的约会 (20)
- PAT (Basic Level) Practise (中文)1002. 写出这个数 (20)