Run ID | 作者 | 问题 | 语言 | 测评结果 | Time | Memory | 代码长度 | 提交时间 |
---|---|---|---|---|---|---|---|---|
115779 | 彭士宝 | 字符串反转 | C++ | Presentation Error | 6 MS | 272 KB | 888 | 2025-04-04 16:25:15 |
#include <iostream> #include <sstream> #include <algorithm> // 用于 std::reverse using namespace std; int main() { int T; // 测试样例的数量 cin >> T; cin.ignore(); // 忽略换行符,确保下一次读取时从第一行的字符串开始 while (T--) { string line; getline(cin, line); // 读取整行字符串 stringstream ss(line); // 使用字符串流分割单词 string word, result; while (ss >> word) { // 逐个读取单词 reverse(word.begin(), word.end()); // 反转单词 result += word + " "; // 将反转后的单词加入结果字符串 } // 去掉最后一个多余的空格 if (!result.empty()) { result.pop_back(); } cout << result << endl; // 输出处理后的字符串 } return 0; }