Run ID | 作者 | 问题 | 语言 | 测评结果 | Time | Memory | 代码长度 | 提交时间 |
---|---|---|---|---|---|---|---|---|
47833 | 葛潇肃 | 单词翻转 | C++ | Accepted | 4 MS | 272 KB | 513 | 2023-05-13 15:06:35 |
#include <iostream> #include <cstring> using namespace std; string s; int main() { getline(cin, s); s = s + ' '; int cnt = 0; int left = 0; int right = 0; for (int i = 0; i < s.size(); i++) { if (s[i] !=' ') { if (cnt == 0) { left = i; } cnt++; } else { if (cnt > 0) { right = i; for (int j = right - 1; j >= left; j--) { cout << s[j]; } cnt = 0; } if (cnt == 0 && i < s.size() - 1) { cout << " "; } } } return 0; }