Run ID | 作者 | 问题 | 语言 | 测评结果 | Time | Memory | 代码长度 | 提交时间 |
---|---|---|---|---|---|---|---|---|
109116 | scscscaa | 字符串反转 | C++ | Presentation Error | 6 MS | 268 KB | 1285 | 2025-01-27 21:52:25 |
#include <iostream> #include <sstream> #include <vector> #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::vector<std::string> words; std::string word; // 分割输入的字符串为单词 while (iss >> word) { words.push_back(word); } std::string result; for (size_t i = 0; i < words.size(); ++i) { // 反转每个单词 std::string reversedWord = reverseWord(words[i]); result += reversedWord; if (i < words.size() - 1) { result += " "; } } 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; }