Text Reverse

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

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.
Hint

Remember to use getchar() to read '\n' after the interger T, then you may use gets() to read a line and process it.

 

Author
Ignatius.L
 
#include <iostream>
#include <cstdio>
#include <cstring>
#include <stack>
using namespace std;
char str[1000];
int main()
{
    int T;
    cin>>T;
    getchar();
while(T--)
{
    stack<char> st;
    gets(str);
    int len=strlen(str);
    int i;
    str[len]=' ';
    for(i=0;i<=len;i++)
    {
        if(str!=' ')
        {
           st.push(str);
        }
        else  if(str==' ')
        {
            while(!st.empty())
            {
                cout<<st.top();
                st.pop();
            }
            if(i!=len)
            cout<<" ";
            else
            cout<<endl;
        }
    }
}
    return 0;
}

HDOJ 1062 Text Reverse的更多相关文章

  1. hdu 1062 Text Reverse 字符串

    Text Reverse                                                                                  Time L ...

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

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

  3. 【HDOJ】1062 Text Reverse

    Ignatius likes to write words in reverse way. Given a single line of text which is written by Ignati ...

  4. 题解报告:hdu 1062 Text Reverse

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

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

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

  6. 1062 Text Reverse

    http://acm.hdu.edu.cn/showproblem.php?pid=1062 思路: 最主要的是通过getline函数存取字符串. 如何读取单个单词,并且反向输出? 用\n作为单个单词 ...

  7. HDU 1062 Text Reverse

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

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

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

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

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

随机推荐

  1. 09-排序3 Insertion or Heap Sort

    和前一题差不多,把归并排序换成了堆排序.要点还是每一次排序进行判断 开始犯了个错误 堆排序该用origin2 结果一直在排序origin ,误导了半天以为是逻辑错误...一直在检查逻辑 建立最大堆 排 ...

  2. 5.python的字符串

    在前面提起过字符串这个词,现在就来学习什么是字符串. 首先,字符串是python内置的数据类型,其特点是用引号引起来,并且可以是使用单引号('字符串'),双引号("字符串"),三个 ...

  3. 转:javascript 中select的取值

    javascript获取select的值全解 获取显示的汉字 document.getElementById("bigclass").options[window.document ...

  4. 【WPF学习日记】——Window的DataContext绑定ViewModel

    1.全局的ViewModel绑定: a)设定全局的ViewModel(App.xaml中): 1 <Application x:Class="MyTest.App" 2 xm ...

  5. Mysql数据库基本配置

    一 数据库基本配置包括编码方式 (安装环境是在linux下) 1.1 进入数据库 开启数据库服务:service mysqld start/restart(如果开启话可以重启) 关闭数据库服务:ser ...

  6. [笔记]一个测试浏览器对html5支持的网站

    用需要测试的浏览器打开这个地址:http://html5test.com/

  7. 68.vivado与modelsim的关联以及器件库编译

    vivado软件中也自带仿真工具,但用了几天之后感觉仿真速度有点慢,至少比modelsim慢挺多的.而modelsim是我比较熟悉的一款仿真软件,固然选它作为设计功能的验证.为了将vivado和mod ...

  8. C++变量的存储类别与作用域

    总结一下C++中变量的存储类别以及变量的作用域. (1)标示符的存储类别决定了标示符在内存中存在的时间(我们可以理解标示符就是确定一个变量的符号,也就是我们所说的变量名) 二:存储类别 (1)静态存储 ...

  9. [shell基础]——paste命令

    测试文本内容如下: # cat name1.txt name1 alvin1 name2 alvin2 name3 alvin3 name4 alvin4 # cat name2.txt name1 ...

  10. xml之Schema架构

    1.什么是Schema架构 2.Schema文档结构  3.Schema元素类型 1>element元素 <!--简单数据:类型--> <xs:element name=&qu ...