HDU 1062 Text Reverse
题意 : 给出你一个句子,让你把句子中每个单词的字母顺序颠倒一下输出。
思路 : 用栈即可,就是注意原来在哪儿有空格就要输出空格。
//hdu1062
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <stack>
using namespace std ;
int main()
{
int n ;
scanf("%d",&n) ;
getchar() ;
char ch[] ;
for(int i = ; i < n ; i++)
{
stack<char>stk ;
gets(ch) ;
int len = strlen(ch) ;
ch[len] = ' ' ;//最后一个单词输出时的空格
ch[len+] = '\0' ;
int len1 = strlen(ch) ;
for(int j = ; j < len1 ; j++)
{
if(ch[j] != ' ')
stk.push(ch[j]) ;
else
{
while(!stk.empty())
{
char sh = stk.top() ;
printf("%c",sh) ;
stk.pop() ;
}
if(j != len1-)
printf("%c",ch[j]) ;//除了最后一个单词后边没有空格之外,其余都有
} }printf("\n") ;
}
return ;
}
HDU 1062 Text Reverse的更多相关文章
- hdu 1062 Text Reverse 字符串
Text Reverse Time L ...
- 题解报告:hdu 1062 Text Reverse
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1062 Problem Description Ignatius likes to write word ...
- HDU 1062 Text Reverse(水题,字符串处理)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1062 解题报告:注意一行的末尾可能是空格,还有记得getchar()吃回车符. #include< ...
- HDOJ/HDU 1062 Text Reverse(字符串翻转~)
Problem Description Ignatius likes to write words in reverse way. Given a single line of text which ...
- [hdu 1062] Text Reverse | STL-stack
原题 题目大意: t组数据,每组为一行,遇到空格时讲前面的单词反转输出. 题解: 显然的栈题,遇到空格时将当前栈输出清空即可 #include<cstdio> #include<st ...
- HDOJ 1062 Text Reverse
Text Reverse Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Tota ...
- 【HDOJ】1062 Text Reverse
Ignatius likes to write words in reverse way. Given a single line of text which is written by Ignati ...
- 1062 Text Reverse
http://acm.hdu.edu.cn/showproblem.php?pid=1062 思路: 最主要的是通过getline函数存取字符串. 如何读取单个单词,并且反向输出? 用\n作为单个单词 ...
- 简单字符串处理 hdu1062 Text Reverse
虽然这个题目一遍AC,但是心里还是忍不住骂了句shit! 花了一个小时,这个题目已经水到一定程度了,但是我却在反转这个操作上含糊不清,并且还是在采用了辅助数组的情况下,关系的理顺都如此之难. 其实我是 ...
随机推荐
- Contoso 大学 - 3 - 排序、过滤及分页
原文 Contoso 大学 - 3 - 排序.过滤及分页 目录 Contoso 大学 - 使用 EF Code First 创建 MVC 应用 原文地址:http://www.asp.net/mvc/ ...
- 第二十九篇、CoreAnimation的使用
使用的的三个步骤 1.初始化演员 2.设置好剧情 3.播放 主要类: CALayer // 绘图部分 CABaseAnimation // 基本动画(缩放,移动) CAKeyframeAnimatio ...
- iOS夯实:内存管理
iOS夯实:内存管理 文章转自 内存管理 最近的学习计划是将iOS的机制原理好好重新打磨学习一下,总结和加入自己的思考. 有不正确的地方,多多指正. 目录: 基本信息 旧时代的细节 新时代 基本信息 ...
- Xcode-项目模板修改
项目模板就是创建工程的时候选择的某一个条目, Xcode会根据选择的条目生成固定格式的项目 例如想创建一个命令行项目就选择Command Line Tool 如何修改项目模板 1.应用程序中,找到Xc ...
- sql语句聚合等疑难问题收集
------------------------------------------------------------------------------------ 除法运算 select 500 ...
- ArcSDE for oracle10g安装后post的时候出现错误
The Post Installation Setup can not locate required Oracle files in your path.Check your Oracle inst ...
- Unity基本操作一
1,使对象进入摄像机镜头内align with view 2,太阳光 创建点point light,调节Intensity改变光照强度,上面的Range改变光照范围. 3,Animation选中Pla ...
- This bison version is not supported for regeneration of the Zend/PHP parsers
在 mac 中编译 php-src.git 报错: configure: WARNING: This bison version is not supported , excluded: ). con ...
- nginx源码分析
ngx_init_cycle 解析配置文件 完成模块中command set函数调用
- iOS Mac系统下Ruby环境安装
由EasyIOS引出的一系列问题:转载的上一篇CocoaPods安装和使用教程中说明了,为什么要使用cocoapods ,但是要安装cocoapods需要Ruby环境,安装Ruby环境首先需要安装Xc ...