Run ID | 作者 | 问题 | 语言 | 测评结果 | Time | Memory | 代码长度 | 提交时间 |
---|---|---|---|---|---|---|---|---|
47834 | 郑九熊 | 单词翻转 | C++ | Accepted | 4 MS | 276 KB | 601 | 2023-05-13 15:17:11 |
//#include <bits/stdc++.h> #include <iostream> #include <string> using namespace std; string s; int main() { //freopen("1468.in", "r", stdin); //freopen("1468.ous t", "w", stdout); getline(cin,s); s += ' '; int a = s.size(); int l = 0; int r = 0; int cnt = 0; for (int i = 0; i < a; i++) { if (s[i] != ' ') { if (cnt == 0) { l = i; } cnt++; } else { if (cnt > 0) { r = i - 1; for (int j = r; j >= l; j--) { cout << s[j]; } cnt = 0; } if (cnt == 0 && s[i] != a - 1) { cout << ' '; } } } return 0; }