《关于我样例过了却一分没有这件事儿啊……》
查看原帖
《关于我样例过了却一分没有这件事儿啊……》
977778
__Harry_Haiyun__楼主2023/8/7 12:06
#include <bits/stdc++.h>
#define MOD 998244353
#define mod 1000000007
#define ll long long
#define ull unsigned long long
#define ui unsigned int
using namespace std;
const int maxn = 1e6+9;
int main()
{
	string str;
    getline(cin,str);
    stack<string>s;
    stack<char>st;
    for (int i = 0; i < str.length(); i++) 
    {
        if (i == str.length() - 1)
        {
            st.push(str[i]);
            string cc = "";
            while (!st.empty())
            {
                cc += st.top();
                st.pop();
            }
            s.push(cc);
            break;
        }
        if (str[i] == ' ')
        {
            string cc = "";
            while (!st.empty())
            {
                cc += st.top();
                st.pop();
            }
            s.push(cc);
        }
        else st.push(str[i]);
    }
    while (!s.empty())
    {
        cout << s.top() << '\n';
        s.pop();
    }
	return 0;
}
2023/8/7 12:06
加载中...