题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1062

Problem Description

Ignatius likes to write words in reverse way. Given a single line of text which is written by Ignatius, you should reverse all the words and then output them.

Input

The input contains several test cases. The first line of the input is a single integer T which is the number of test cases. T test cases follow.
Each test case contains a single line with several words. There will be at most 1000 characters in a line.

Output

For each test case, you should output the text which is processed.

Sample Input

3
olleh !dlrow
m'I morf .udh
I ekil .mca

Sample Output

hello world!
I'm from hdu.
I like acm.

解题思路:问题求解的是每个句子中每个单词的反转。

AC代码一之C代码:

 #include<bits/stdc++.h>
using namespace std;
char a[];
int main()
{
int T,len,x,y;
while(cin>>T){
getchar();//吃掉回车符
while(T--){
gets(a);
len=strlen(a);
for(int i=;i<len;++i){
x=i;//标记当前单词的起始坐标
while(a[i]!=' ' && a[i]!='\0')++i;//循环直到遇到空字符
y=i-;//标记单词尾坐标
for(int j=y;j>=x;--j)
printf("%c",a[j]);//反序输出
if(a[i]==' ')cout<<' ';//如果此时a[i]是空字符的话顺便输出
}
cout<<endl;//换行
}
}
return ;
}

AC代码二之C++代码:

 #include<bits/stdc++.h>
using namespace std;
int t;string str,tmp;size_t pos,pre;
int main(){
while(cin>>t){
getchar();
while(t--){
getline(cin,str);pre=pos=;//初始定位为0
while((pos=str.find(" ",pos))!=string::npos){
tmp=str.substr(pre,pos-pre);//每次从pos位置开始截取pos-pre个字符
reverse(tmp.begin(),tmp.end());//反转字符串
cout<<tmp<<' ';//输出并且带空格输出
pre=++pos;//pre指向下一个位置
}
tmp=str.substr(pre);//获取最后的一个单词
reverse(tmp.begin(),tmp.end());//反转字符串
cout<<tmp<<endl;//直接输出并且换行
}
}
return ;
}

题解报告:hdu 1062 Text Reverse的更多相关文章

  1. hdu 1062 Text Reverse 字符串

    Text Reverse                                                                                  Time L ...

  2. HDU 1062 Text Reverse(水题,字符串处理)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1062 解题报告:注意一行的末尾可能是空格,还有记得getchar()吃回车符. #include< ...

  3. HDOJ/HDU 1062 Text Reverse(字符串翻转~)

    Problem Description Ignatius likes to write words in reverse way. Given a single line of text which ...

  4. [hdu 1062] Text Reverse | STL-stack

    原题 题目大意: t组数据,每组为一行,遇到空格时讲前面的单词反转输出. 题解: 显然的栈题,遇到空格时将当前栈输出清空即可 #include<cstdio> #include<st ...

  5. HDU 1062 Text Reverse

    题意 : 给出你一个句子,让你把句子中每个单词的字母顺序颠倒一下输出. 思路 : 用栈即可,就是注意原来在哪儿有空格就要输出空格. //hdu1062 #include <iostream> ...

  6. HDOJ 1062 Text Reverse

    Text Reverse Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Tota ...

  7. 【HDOJ】1062 Text Reverse

    Ignatius likes to write words in reverse way. Given a single line of text which is written by Ignati ...

  8. 1062 Text Reverse

    http://acm.hdu.edu.cn/showproblem.php?pid=1062 思路: 最主要的是通过getline函数存取字符串. 如何读取单个单词,并且反向输出? 用\n作为单个单词 ...

  9. 简单字符串处理 hdu1062 Text Reverse

    虽然这个题目一遍AC,但是心里还是忍不住骂了句shit! 花了一个小时,这个题目已经水到一定程度了,但是我却在反转这个操作上含糊不清,并且还是在采用了辅助数组的情况下,关系的理顺都如此之难. 其实我是 ...

随机推荐

  1. 如何把你的Windows PC变成瘦客户机

    越来越多的用户开始使用vmware view 4.5来做为企业桌面虚拟化的平台,通过view,所有的管理工作都转移到数据中心,但是考虑到成本原因,很多人员还在使用PC机,有没有办法将PC机变成瘦客户机 ...

  2. 一个基于JBoss5.1+EJB3.0 登陆应用

    花了几天的时间研究了一下EJB的使用,一直以来都主要是在写终端中的程序,对Java框架的相关的开发非常不熟悉,中间遇到了不少麻烦,还好总算都攻克了.写篇日志记录一下. 经验总结 为什么选择JBoss5 ...

  3. 自定义的强大的UITableViewCell

    UITableView的强大更多程度上来自于可以任意自定义UITableViewCell单元格.通常,UITableView中的Cell是动态的,在使用过程中,会创建一个Cell池,根据每个cell的 ...

  4. 亲測Mysql表结构为InnoDB类型从ibd文件恢复数据

    客户的机器系统异常关机,重新启动后mysql数据库不能正常启动,重装系统后发现数据库文件损坏,悲催的是客户数据库没有进行及时备份,仅仅能想办法从数据库文件其中恢复,查找资料,试验各种方法,确认以下步骤 ...

  5. 生成随机string

    转自:http://blog.csdn.net/yaodong_y/article/details/8115250 字母与数字的ASCII码 目 前计算机中用得最广泛的 字符集及其编码,是由美国国家标 ...

  6. 连接sql2008时报错

    最近把公司的项目搭建到本地(周末回家要加班),可是连接后,发现程序后台出错,错误信息:不支持此服务器版本.目标服务器必须是 SQL Server 2000 或更高版本. 本地是SqlServer200 ...

  7. ES6 模块化(Module)export和import详解 export default

    ES6 模块化(Module)export和import详解 - CSDN博客 https://blog.csdn.net/pcaxb/article/details/53670097 微信小程序笔记 ...

  8. Linux的进程优先级NI和PR到底有什么区别

    Linux的进程优先级NI和PR到底有什么区别 - 51CTO.COM http://os.51cto.com/art/201605/511559.htm

  9. easyUI下拉列表点击事件的使用

    可以通过input 和select来创建下拉列表 其中select的创建如下: 通过json来创建js数组 [{ "id":1, "text":"te ...

  10. jQuery简单纯文字提示条

    如何制作jQuery简单纯文字提示条,先介绍提示条(tooltip)的意思是用户鼠标悬停经过事件发生提示title.它们已经呈现在大多数浏览器中,当你可以提供一个链接或图片的title属性,就是用户将 ...