3 单词反转: 对一个输入的单词反转 例如输入 I am a student. 则输出 .tneduts a ma I

/*
3 单词反转:
对一个输入的单词反转
例如输入 I am a student.  则输出 .tneduts a ma I
*/

#include<iostream>
#include<stdio.h>
#include<stack>
using namespace std;

int main()
{
	stack<char> s;
	char n;
	cout << "输入需要反转的字符串:" << endl;
	n = getchar();
	while (n != '\n')
	{
		s.push(n);
		n = getchar();
	}
	while (!s.empty())
	{
		cout << s.top();
		s.pop();
	}
	cout << endl;
	system("pause");
	return 0;
}
发布了96 篇原创文章 · 获赞 96 · 访问量 22万+

猜你喜欢

转载自blog.csdn.net/qq_33221533/article/details/94021757