有点抽象了
  • 板块B2122 单词翻转
  • 楼主xwfro
  • 当前回复3
  • 已保存回复3
  • 发布时间2024/8/8 20:49
  • 上次更新2024/8/8 21:48:57
查看原帖
有点抽象了
383198
xwfro楼主2024/8/8 20:49

貌似有点太抽象了,这道题,我这能全WA

#include <cstring>
#include <iostream>
#include <stack>
std::string s;
std::stack<char> st;
int main()
{
    std::getline(std::cin, s);
    int n = s.length();
    for (int i = 0; i < n; i++)
    {
        if (s[i] != ' ')
            st.push(s[i]);
        else
        {
            while (!st.empty())
            {
                std::cout << st.top();
                st.pop();
            }
            std::cout << std::endl;
        }
    }
    while (!st.empty())
    {
        std::cout << st.top();
        st.pop();
    }
    return 0;
}
2024/8/8 20:49
加载中...