说反话 栈实现

利用栈 能很快解决该问题

#include <iostream>
#include <stack>
using namespace std;
#include <string>
int main()
{
	stack<string>str_stack;
	string s;
	cin >> s;
	str_stack.push(s);
	while (getchar() != '\n') {
		cin >> s;
		str_stack.push(s);
	}
	//依次出栈  打印栈顶元素
	while (!str_stack.empty()) {
		cout << str_stack.top() << " ";
		str_stack.pop();
	}
	return 0;
}

在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/qq_42673507/article/details/85231909