1009 说反话 pat

来源:互联网 发布:生意宝,网络小贷牌照 编辑:程序博客网 时间:2024/05/06 19:59
#include<iostream>
#include <string>
#include <stack>
using namespace std;


string FanZhuan(string temp)
{
stack<string> stack;
stack.push("&&");
string str;
int fir = 0, sec = 0;
int i = 0;
while (true)
{
if ((temp[i] != ' ')&&temp[i] != 0)
{
i += 1;
continue;
}
else if(temp[i] == 0)
{
stack.push(temp.substr(fir,i));
break;
}
else
{
stack.push(temp.substr(fir, i-fir));
fir = i+1;
i += 1;
}
}
while (stack.top() != "&&")
{
str += stack.top();
str += " ";
stack.pop();
}
    return str.substr(0,str.size()-1);
}
int main()
{
string temp;
getline(cin, temp);
cout<<FanZhuan(temp);




}
0 0
原创粉丝点击