Text Reverse

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 51495    Accepted Submission(s): 19692

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.
 
首先这个题就是简单的字符串反转,注意点是遇到空格怎么处理,用STL中的栈来模拟
代码:
#include <bits/stdc++.h>

using namespace std;

int main()
{
int n;
char ch;
cin>>n;
getchar();
while(n--){
stack<char>s;
while(true){
ch = getchar();
if(ch==' '||ch=='\n'||ch==EOF){
while(!s.empty()){
cout<<s.top();
s.pop();
}
if(ch=='\n'||ch==EOF)
break;
cout<<" ";
}
else
s.push(ch);
}
cout<<endl;
}
return ;
}

stack的使用-Hdu 1062的更多相关文章

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

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

  2. hdu 1062 Text Reverse 字符串

    Text Reverse                                                                                  Time L ...

  3. 题解报告:hdu 1062 Text Reverse

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1062 Problem Description Ignatius likes to write word ...

  4. HDU 1062 Text Reverse

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

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

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

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

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

  7. HDU - 1062

    格式错误2遍:没考虑到连续两个空格的情况,遇到空格最后要输出这个空格,因为题目只需要转换单词. 另外,开cin,cout加速要注意读入不能用scanf,printf,puts,getchar这些.ge ...

  8. hdu 1062(DFS||dijkstra)

    昂贵的聘礼 Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 44870   Accepted: 13259 Descripti ...

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

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

随机推荐

  1. 如何在linux安装ruby2.2.2+

    背景: 想搭建redis集群但是提示需要ruby2.2.2+ 直接使用yum安装 yum -y install ruby ruby-devel rubygems rpm-build 使用ruby -v ...

  2. mysql存储表情报错

    数据库版本:mysql  Ver 8.0.16 数据库字符集:utf8 原因:mysql的utf8编码的一个字符最多3个字节,但是一个emoji表情为4个字节,所以utf8不支持存储emoji表情.但 ...

  3. 微信个人支付接口---YunGouOS 1.1.3 版本发布,新增个人微信/支付宝收款接口

    软件接口  https://www.oschina.net/news/113305/yungouos-1-1-3-released 文档说明  https://www.oschina.net/p/Yu ...

  4. NABCD model作业

    1)N(Need需求) 随着人类生活的快速发展,给人们带来了许多的便利,同时也给我们带来了一些麻烦,而我的拼图这个小游戏可以在人们在无聊时玩一玩,也可以给小孩子开发智力. 2)A(Approach做法 ...

  5. 503,display:none;与visibility:hidden;的区别

    联系:他们都能让元素不可见 区别: display:none:会让元素从渲染树中消失,渲染的时候不占据任何空间: visibility:hidden:不会让元素从渲染树中消失,渲染时袁旭继续占据空间, ...

  6. jvm字节码助记符

    反编译指令 javap -c xxxx.class JVM参数设置 -xx:+<option>                  开启option -xx: -<option> ...

  7. C语言中二维数组如何申请动态分配内存

    C语言中二维数组如何申请动态分配内存: 使用malloc函数,先分配第一维的大小,然后再循环分配每一维的大小 #include <stdio.h> #include <malloc. ...

  8. JS数组删除

    --------------let items=['a','1',0,2,100,null,NaN,undefined,]; -------------要求以上数据执行后输出['1',0,2,100] ...

  9. django ForeignKey ManyToMany 前后端联动

    总结 外键基本和普通的字段是一样的 多对多 获取 getlist() 更新 clear() add() remove() 前端和后端是通过字符串沟通的,所以使用ajax的时候如果是数据类型,记得要JS ...

  10. List(数组)里面常用的属性和方法

    常用属性: length 长度 reversed 翻转 isEmpty 是否为空 isNotEmpty 是否不为空常用方法: add 增加 addAll 拼接数组 增加多个数据 list.addAll ...