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. javascript当中局部变量和全局变量

    2)局部变量和全局变量 马克-to-win:浏览器里面 window 就是 global,通常可以省.nodejs 里没有 window,但是有个叫 global 的.例 3.2.1<html& ...

  2. 【外文阅读】Web Development in 2020: What Coding Tools You Should Learn---Quincy Larson

    原文链接:https://mail.qq.com/cgi-bin/readtemplate?t=safety&check=false&gourl=https%3A%2F%2Fwww.f ...

  3. Catalyst9K设备介绍

    Catalyst9K系列的里面包含了多款交换机,以及无线控制器,甚至包含了无线AP,如下将简单的介绍这几款产品的情况: 首先,这是一种总体的对应关系: 1.Catalyst9200 Series 主要 ...

  4. Day1 面向对象编程与Java核心类

    this变量 在方法内部,可以使用一个隐含的变量this,它始终指向当前实例.如果没有命名冲突,可以省略this. 但是,如果有局部变量和字段重名,那么局部变量优先级更高,就必须加上this. 构造方 ...

  5. vim配置之——ctags与TagList的配置以及NERDTree && doxygentoolkit的安装

    参考(2)vim插件:显示树形目录插件NERDTree安装 和 使用 本文档主要对Linux下vim的ctags,TagList,NerdTree与doxgentoolkit进行相关的配置. 以下部分 ...

  6. jquery 获取 父级 iframe 里的控件对象

    window.parent.document.getElementsByTagName('iframe')[0].contentWindow.document.getElementById('id')

  7. JS中for循环“全局”变量的传递

    在项目中,遇到了一个问题,描述如下:我们在联动下拉框中,选中值后,会在隐藏的控件中记录一下选中值的主键(展示的是名称).但是,在取消选中的时候,没有把隐藏控件中的value值清空,导致在提交的时候,有 ...

  8. liux 命令行

    查找文件 () find / -name httpd.conf #在根目录下查找文件httpd.conf,表示在整个硬盘查找 () find /etc -name httpd.conf #在/etc目 ...

  9. 如何修改mysql 默认引擎为InnoDB?

    1.查看 MySQL支持的引擎有哪些? show engines: 结果: 由上图可以看出,只有 InnoDB 是支持事务的 2.查看默认引擎 show variables like “default ...

  10. 全排列dfs

    #include <iostream> #include <vector> using namespace std; vector<int> ans; const ...