`
linest
  • 浏览: 151181 次
  • 性别: Icon_minigender_1
  • 来自: 内蒙古
社区版块
存档分类
最新评论

ZOJ-1295 字符串逆序

    博客分类:
  • acm
 
阅读更多
1295:字符串逆序输出

Sample Input

3
Frankly, I don't think we'll make much
money out of this scheme.
madam I'm adam


Sample Output

hcum ekam ll'ew kniht t'nod I ,ylknarF
.emehcs siht fo tuo yenom
mada m'I madam

简单题。。 借助stl库 algorithm中 reverse函数。
读取用到gets(char*) 含空白符的整行读取 getchar 读取单字符。
#include<iostream>
using namespace std;
#include<cstring>
#include<algorithm>
#include<stdio.h>

int main()
{
	string s;
	char src[70];
	int n;
	cin>>n;
	getchar(); //把换行符读走,下面按行读取
	for(int i=0;i<n;i++)
	{
		gets(src);
		s = string(src);
		reverse(s.begin(),s.end());
		cout<<s.c_str()<<endl;;
	}
	
}

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics