Run ID:109119

提交时间:2025-01-27 21:57:14

#include <iostream> #include <sstream> #include <algorithm> #include <string> // 反转单个单词 std::string reverseWord(const std::string& word) { std::string reversedWord = word; std::reverse(reversedWord.begin(), reversedWord.end()); return reversedWord; } // 处理单个测试样例 std::string processTestCase(const std::string& testCase) { std::istringstream iss(testCase); std::string word; std::string result; bool firstWord = true; // 分割输入的字符串为单词 while (iss >> word) { // 反转每个单词 std::string reversedWord = reverseWord(word); if (!firstWord) { result += " "; } result += reversedWord; firstWord = false; } return result; } int main() { int T; std::cin >> T; std::cin.ignore(); // 忽略输入T后的换行符 for (int i = 0; i < T; ++i) { std::string testCase; std::getline(std::cin, testCase); // 处理测试样例 std::string output = processTestCase(testCase); std::cout << output << std::endl; } return 0; }