题目链接: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. 【effective c++】模板与泛型编程

    模板元编程:在c++编译器内执行并于编译完成时停止执行 1.了解隐式接口和编译期多态 面向对象编程总是以显式接口(由函数名称.参数类型和返回类型构成)和运行期多态(虚函数)解决问题 模板及泛型编程:对 ...

  2. Ulua_toLua_基本案例(一)

    Ulua_toLua_基本案例 在Untiy中用Lua.必需要LuaInterface.LuaInterface的介绍请看:点击打开链接 能够先光写Lua,生成.lua的纯文件.再Unity中通过,l ...

  3. react 从零开始搭建开发环境

    1.创建 package.json 项目 npm init 2.安装 webpack, 并且设置为项目依赖: npm install webpack --save-dev 当然你必须之前已经在 -g ...

  4. 利用shuf对数据记录进行随机采样

    最近在用SVM为分类器做实验,但是发现数据量太大(2000k条记录)但是训练时间过长...让我足足等了1天的啊!有人指导说可以先进行一下随机采样,再训练,这样对训练结果不会有太大影响(这个待考证).所 ...

  5. sysinfo 系统调用

    在分析luci时,看到 usr/lib/luci/sys.lua 里调用 nixio.sysinfo().这是一个c调用lua的用例.在nixio的代码process.c里导出了给lua调用的接口.在 ...

  6. How can I pass data from Flask to JavaScript in a template?

    https://stackoverflow.com/questions/11178426/how-can-i-pass-data-from-flask-to-javascript-in-a-templ ...

  7. 使用C#开发HTTP服务器系列之Hello World

    各位朋友大家好,我是秦元培,欢迎大家关注我的博客.从今天起,我将开始撰写一组关于HTTP服务器开发的系列文章.我为什么会有这样的想法呢?因为人们对Web技术存在误解,认为网站开发是Web技术的全部.其 ...

  8. 【HAOI2007】反素数

    [题目链接] 点击打开链接 [算法] 稍加分析可知,问题等价于“求1到n中,因子个数最多的数,若有多个,求最小的” 那么我们该怎么求这个数呢? 约数个数定理 : x = p1^a1p2^a2p3^a3 ...

  9. SimpliciTI协议栈

    SimpliciTI组网过程介绍 1.SimpliciTI支持点对点和星形的网络拓扑结构.   下面介绍以AP为中心的SimpliciTI网路协议的星形拓扑结构通信过程 1)当ED节点上电之后就扫描信 ...

  10. artemplate include

    include用于嵌入字模板 {{include 'template_name'}} 子模板 默认共享当前的数据 也可以自己指定数据 {{include 'template_name' templat ...