题目链接: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. 【Linux编程】进程终止和exit函数

    内核要运行一个应用程序,唯一的途径是通过系统调用.exec函数.exec又会调用启动程序,启动程序(一般是汇编语言)以类似以下的方式调用main函数: void exit(main(argc, arg ...

  2. C语言 字符串操作 笔记

    /* C语言字符串的操作笔记 使用代码和注释结合方式记录 */ # include <stdio.h> # include <string.h> int main(void) ...

  3. android 开发中用到的工具-持续更新(码农必看)

    1. vim 单文件查看改动利器(一直使用支持各种编码各种文件,各种插件),欢迎下载笔者插件 git clone https://github.com/green130181/vim-conf.git ...

  4. AWK教程

    1. IBM:GAWK入门:AWK语言基础 2. Unix AWK使用手册 3. 台湾中研院计算中心ASPAC计划之AWK程序介绍 4. Study-area之AWK 5. AWK学习笔记——酷勤 持 ...

  5. 常见网络摄像机默认使用的端口,RTSP地址

    品牌 默认IP地址 WEB RTSP HTTPS 数据 ONVIF   海康威视 192.168.1.64/DHCP用户名admin 密码自己设 80 554 443 8000 80   大华 192 ...

  6. ExtJs里表格自动显隐滚动条

    ExtJs里面,layout:'border'这种布局应该很常用,但我用的时候,因为不熟,走了一些弯路.比如说,一个页面,大体布局是这样的: 上:查询输入框 中+下:查询结果(表格,底部有分页控件) ...

  7. 2016/05/10 thinkphp 3.2.2 ①系统常量信息 ②跨控制器调用 ③连接数据库配置及Model数据模型层 ④数据查询

    [系统常量信息] 获取系统常量信息: 如果加参数true,会分组显示: 显示如下: [跨控制器调用] 一个控制器在执行的时候,可以实例化另外一个控制,并通过对象访问其指定方法. 跨控制器调用可以节省我 ...

  8. C# 敏感词过滤

    public class BadWordFilter { #region 变量 private HashSet<string> hash = new HashSet<string&g ...

  9. What Is the Linux Lokkit Utility? https://www.lifewire.com/what-is-lokkit-2192255

    lokkit: The Lokkit utility attempts to provide firewalling for the average Linux end user. Instead o ...

  10. Win7下安装iMac系统

    首先是灰常激动啊,一下午的努力最终在自己华硕的笔记本上安装了mac系统. 先上一个成果截图 watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQveXl4aGh4/ ...