Run ID 作者 问题 语言 测评结果 Time Memory 代码长度 提交时间
115780 彭士宝 字符串反转 C++ Presentation Error 5 MS 264 KB 847 2025-04-04 16:45:00

Tests(0/1):


Code:

#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; string result; while (ss >> word) { // 逐个单词读取 reverse(word.begin(), word.end()); // 反转单词 result += word + " "; // 将反转后的单词拼接到结果中 } if (!result.empty()) { result.pop_back(); // 去掉最后一个多余的空格 } cout << result << endl; // 输出处理后的结果 } return 0; }