7-138 4114 单词逆序

#include <algorithm>
#include <cstdint>
#include <iostream>
#include <limits>
#include <numeric>
#include <string>
#include <unordered_map>
#include <utility>
#include <vector>

using i32 = std::int32_t;
using i64 = std::int64_t;
using u32 = std::uint32_t;
using u64 = std::uint64_t;
using pii = std::pair<i32, i32>;
using pll = std::pair<i64, i64>;
using vi = std::vector<i32>;
using vll = std::vector<i64>;
using vpii = std::vector<pii>;
using vpll = std::vector<pll>;

void solve();

int main()
{
    std::cin.tie(nullptr)->sync_with_stdio(false);
    solve();
}

template <typename T> std::vector<std::string> split(T &&s, char dot = '.')
{
    std::vector<std::string> res;
    std::string temp;
    for (const auto &item : s)
    {
        if (item == dot)
        {
            res.emplace_back(std::move(temp));
            temp.clear();
            continue;
        }
        temp += item;
    }
    if (!temp.empty())
    {
        res.emplace_back(std::move(temp));
    }
    return res;
}

void solve()
{
    i32 t;
    std::cin >> t;
    bool endl{false};
    while (--t >= 0)
    {
        if (endl)
        {
            std::cout << "\n\n";
        }
        i32 n;
        std::cin >> n;
        std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
        bool endl2{false};
        for (i32 i = 1; i <= n; ++i)
        {
            if (endl2)
            {
                std::cout << '\n';
            }
            std::string str;
            std::getline(std::cin, str);
            bool space{false};
            for (auto &&word : split(str, ' '))
            {
                if (space)
                {
                    std::cout << ' ';
                }
                for (u64 j = word.length() - 1; j >= 0 && j <= word.length() - 1; --j)
                {
                    std::cout << word[j];
                }
                space = true;
            }
            endl2 = true;
        }
        endl = true;
    }
}
posted @ 2025-10-15 08:44  TPPPP72  阅读(6)  评论(0)    收藏  举报