单词反转
Problem Description
给你一些英文句子,请将这些句子中的每个英语单词反转,然后再将其输出.这里听说的英语单词仅由大小写英文字母组成.
Input
多个英文句子,每句占一行,且每句不超过80个字符.
Output
按题目要求输出
Sample Input
Hello world!
Sample Output
olleH dlrow!
解释:
具体解释见代码。,注意是,字母反转,其他的字符的字符串不要转,之前没有注意,全部反转了,于是果断错误。

1 #include<bits/stdc++.h> 2 3 using namespace std; 4 5 int main(){ 6 7 int i, j, k; 8 char str[81], t[81]; 9 10 while (gets(str)) 11 { 12 k = 0; 13 for (i = 0; str[i]; i++){ 14 if ((str[i] >= 'A' && str[i] <= 'Z') || (str[i] >= 'a' && str[i] <= 'z')){ 15 t[k++] = str[i]; 16 } else { 17 for (j = k - 1; j >= 0; j--){ 18 cout << t[j]; 19 } 20 cout << str[i]; 21 k = 0; 22 } 23 } 24 for (j = k - 1; j >= 0; j--) { 25 cout << t[j]; 26 } 27 cout << endl; 28 } 29 }