给定一句英语,要求你编写程序,将句中所有单词的顺序颠倒输出。
输入格式:测试输入包含一个测试用例,在一行内给出总长度不超过80的字符串。字符串由若干单词和若干空格组成,其中单词是由英文字母(大小写有区分)组成的字符串,单词之间用1个空格分开,输入保证句子末尾没有多余的空格。
输出格式:每个测试用例的输出占一行,输出倒序后的句子。
输入样例:
Hello World Here I Come
输出样例:
Come I Here World Hello
1 #include<cstdio> 2 #include<iostream> 3 #include<cmath> 4 #include<cstring> 5 using namespace std; 6 7 int main() 8 { 9 char a[85]; 10 char b[85]; 11 gets(a); 12 int len=strlen(a),k=0; 13 bool flag=0; 14 for(int i=len-1;i>=0;i--) 15 { 16 if(a[i]==' ') 17 { 18 if(flag!=0) 19 printf(" "); 20 else 21 flag=1; 22 for(int j=k-1;j>=0;j--) 23 printf("%c",b[j]); 24 k=0; 25 } 26 else if(i==0) 27 { 28 if(flag!=0) 29 printf(" "); 30 else 31 flag=1; 32 b[k++]=a[i]; 33 for(int j=k-1;j>=0;j--) 34 printf("%c",b[j]); 35 } 36 else 37 { 38 b[k++]=a[i]; 39 } 40 } 41 return 0; 42 }