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. Python学习(学习视频b站小甲鱼)

    001讲 0. Python 是什么类型的语言? Python是脚本语言以简单的方式快速完成某些复杂的事情通常是创造脚本语言的重要原则. 特性: 语法和结构通常比较简单 学习和使用通常比较简单 通常以 ...

  2. JavaWeb01-动态网页

    01.动态网页的优势 动态网页是在服务器端运行的程序!随不同用户,不同条件 返回不同的结果! 001.交互性:网页会根据用户的要求和选择而动态的改变和现实网页内容! 002.自动更新:无需改变页面的代 ...

  3. Multisim 如何调整编辑界面大小

    1.option -> sheet properties 2.选择workspace

  4. 用eclipse发布springboot项目

    使用eclipse打包springboot项目时一直报错 [ERROR] No compiler is provided in this environment. Perhaps you are ru ...

  5. Day2 异常 日志 反射

    调用方如何获知调用失败的信息? 1.约定返回错误码.处理一个文件,如果返回0,表示成功,返回其他整数,表示约定的错误码: 2.在语言层面上提供一个异常处理机制 异常 异常是一种class,因此它本身带 ...

  6. Vue集成openlayers

    1.安装ol库 使用cnpm i ol -s命令安装 2.建一个olMap.vue文件夹 <template> <div class='olMap'> <h2>{{ ...

  7. 自定义控件之绘图篇(四):canvas变换与操作

    具体操作见下面链接: http://blog.csdn.net/harvic880925/article/details/39080931/

  8. Ubuntu执行sudo apt-get update报错E: 无法获得锁 /var/lib/apt/lists/lock - open (11: 资源暂时不可用) E: 无法对目录 /var/lib/apt/lists/ 加锁

    一.强制解锁,执行语句 sudo rm /var/lib/apt/lists/lock 二.终端输入 ps -aux | grep apt-get 查看一下apt-get的相关进程.然后sudo ki ...

  9. Sql性能优化梳理

    前言 先简单梳理下Mysql的基本概念,然后分创建时和查询时这两个阶段的优化展开. 1.0 基本概念简述 1.1 逻辑架构 第一层:客户端通过连接服务,将要执行的sql指令传输过来 第二层:服务器解析 ...

  10. PTA的Python练习题(十八)

    第4章-20 求矩阵各行元素之和 遇到一个麻烦的事情: 上面a,b输入,如果一起输入转int会报错,因为int只能一对一 但是明明我分开来int了,下面第十行还是报错说我的b是string字符,难不成 ...