標簽:blog class com code img http div java size javascript style
給定一句英語,要求你編寫程序,將句中所有單詞的順序顛倒輸出。
輸入格式:測試輸入包含一個測試用例,在一行內給出總長度不超過80的字符串。字符串由若幹單詞和若幹空格組成,其中單詞是由英文字母(大小寫有區分)組成的字符串,單詞之間用1個空格分開,輸入保證句子末尾沒有多余的空格。
輸出格式:每個測試用例的輸出占一行,輸出倒序後的句子。
輸入樣例:
Hello World Here I Come
輸出樣例:
Come I Here World Hello
1 #include<stdio.h> 2 #include<string.h> 3 #define MAXN 80+10 4 #define HALFMAXN 40+5 5 char input[MAXN]; 6 char output[HALFMAXN][MAXN]; 7 int main(){ 8 int i = 0,j=0,num = 0; 9 memset(input,0,sizeof(input)); 10 memset(output,0,sizeof(output)); 11 12 gets(input); 13 for(;i < sizeof(input); i++){ 14 15 if(input[i] == ‘ ‘){ 16 j = 0; 17 num++; 18 continue; 19 } 20 /*if(input[i] == 0){ 21 break; 22 }*/ 23 output[num][j++] = input[i]; 24 } 25 26 //由于最後不能有空格,因此不能num>=0 27 for(; num > 0; num--){ 28 printf("%s ",output[num]); 29 } 30 printf("%s\n",output[num]); 31 return 0; 32 }
PAT 1009 说反话 C语言,码迷,mamicode.com
標簽:blog class com code img http div java size javascript style
原文地址:http://www.cnblogs.com/fyymonica/p/3694609.html