码迷,mamicode.com
首页 > 编程语言 > 详细

HD-ACM算法专攻系列(7)——Text Reverse

时间:2017-10-07 17:47:50      阅读:184      评论:0      收藏:0      [点我收藏+]

标签:print   for   lin   ext   class   mes   div   cout   eve   

问题描述:

技术分享

技术分享

 

 源码:

 

/**/
#include"iostream"
#include"string"
using namespace std;

void Print(string str, int end, int start)
{
	for(int i = end; i >= start; i--)cout<<str[i];
}

int main()
{
	int n, start, end;
	string str;
	while(cin>>n)
	{
		getchar();
		for(int i = 0; i < n; i++)
		{
			getline(cin, str);
			start = end = 0;
			for(int j = 0; j < str.length(); j++)
			{
				if(str[j] == ‘ ‘)
				{
					end = j - 1;
					if(start != 0)cout<<" ";
					Print(str, end , start);
					start = j + 1;
				}
			}
			if(start != 0)cout<<" ";
			Print(str, str.length() - 1, start);
			cout<<endl;
		}
	}
    return 0;
}

  

HD-ACM算法专攻系列(7)——Text Reverse

标签:print   for   lin   ext   class   mes   div   cout   eve   

原文地址:http://www.cnblogs.com/forcheng/p/7634867.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!