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. WebForm与MVC混用

    步骤一:添加引用 -> 程序集 -> 扩展 -> System.Web.Mvc ; System.Web.Razor; System.Web.WebPages; System.Web ...

  2. sqlalchemy - day4

    query 此文算是自己的一个总结,不敢说对sqlalchemy有多精通,只能算是入门的总结,免得后面忘记了这些个基本的东西.数据库的增,删,改,查,前面已经介绍了session的增,删,改,现在来介 ...

  3. [转载]--类unix系统如何初始化shell

    Shell的配置文件 当我们在linux中打开一个shell的时候,系统会读取相关的配置文件来初始化shell(其他unix-like OS也一样).配置文件包括以下这些: 1. 全局配置(对所有用户 ...

  4. Debug.print的用法

    使用Debug.print可以用来更好的调试VBA程序 通过ALT+F11代开VBA编程窗口) 插入模块,接着在窗口中输入以下代码,按F5执行 Sub Excute() Debug.Print * + ...

  5. 批处理判断是否存在文件,存在则运行另外一个bat文件

    现在需求如下: 使用bat文件判断是否存在ktr文件,存在则运行pan.bat,执行kettle脚本. 代码如下: @echo off @title 批处理判断文件夹是否存在 cd /d F: rem ...

  6. VBA在WORD中给表格外的字体设置为标题

    使用VB可以将表外的字体设置标题字体实际操作如下: VB代码如下: Sub oliver_1() Selection.EndKey Unit:=wdStory '光标移到文末 To ActiveDoc ...

  7. 关于EF分页查询报错(Count must have a non-negative value.)的解决方案

    具体的异常信息如下,一开始没有写日志只看到错误信息:Count must have a non-negative value.,从表面意思可以看出来是Count值出现了负数,所以报错,查了半天的原因也 ...

  8. oracle分区表(整理)

    Oracle 表分区 早在8.0.5版本中,Oracle就将范围分区技术引入,现在分区功能已经越来越强大,包括支持扩展分区功能.Interval分区.外键分区.模拟列分区.以及分区建议器等.那么,分区 ...

  9. ubuntu 修改ssh远程主机名称,mac开机运行命令,静默方式启动virtual box虚拟机,静默执行run脚本

    一.修改主机名 ssh登陆 vi /etc/hostname vi /etc/hosts hostname ulocal (执行这个命令,无须重启服务器) 保证127.0.0.1 的hostname与 ...

  10. C#判断字符串为空

    string str = null; if (string.IsNullOrWhiteSpace(str)) { MessageBox.Show("字符串为null"); } if ...