思路:遇到空格就输出空格前的字符串,最后一个字符串单独输出
#include <iostream> #include <cstring> using namespace std; int main() { char s[1005]; int n; cin >> n; getchar(); while (n--) { gets(s); int k = 0; int m = strlen(s); for (int i = 0; i < m; i++) { if (s[i] == ‘ ‘) { for (int j = i - 1; j >= k; j--) { cout << s[j]; } cout << " "; k = i + 1; } } for (int i = m - 1; i >= k; i--) { cout << s[i]; } cout << endl; } }
原文:https://www.cnblogs.com/FantasticDoubleFish/p/14310140.html