HDOJ/HDU 1062 Text Reverse(字符串翻转~)
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.
题意:
输入一行字符串,将每一个单词(只有空格隔开)倒序输出!
注意:
开始和结尾可能有多个空格,单词之间可能有多个空格!
PE的请注意:空格必须照原样输出!有几个输出几个,不能多输出也不能少输出!
import java.util.Scanner;
/**
* @author 陈浩翔
* 2016-5-25
*/
public class Main{
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int t =sc.nextInt();
sc.nextLine();//读取输入t之后的回车
while(t-->0){
String str=sc.nextLine();
String s[] = str.split(" ");
String str2="";
for(int i=0;i<s.length;i++){
for(int k=s[i].length()-1;k>=0;k--){
System.out.print(s[i].charAt(k));
str2+=s[i].charAt(k);
}
if(i!=s.length-1){
System.out.print(" ");
str2+=" ";
}
}
for(int i=str2.length();i<str.length();i++){
System.out.print(" ");
}
System.out.println();
}
}
}
HDOJ/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 解题报告:注意一行的末尾可能是空格,还有记得getchar()吃回车符. #include< ...
- 题解报告:hdu 1062 Text Reverse
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1062 Problem Description Ignatius likes to write word ...
- 【HDOJ】1062 Text Reverse
Ignatius likes to write words in reverse way. Given a single line of text which is written by Ignati ...
- HDU 1062 Text Reverse
题意 : 给出你一个句子,让你把句子中每个单词的字母顺序颠倒一下输出. 思路 : 用栈即可,就是注意原来在哪儿有空格就要输出空格. //hdu1062 #include <iostream> ...
- [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 ...
- 1062 Text Reverse
http://acm.hdu.edu.cn/showproblem.php?pid=1062 思路: 最主要的是通过getline函数存取字符串. 如何读取单个单词,并且反向输出? 用\n作为单个单词 ...
- HDOJ/HDU 1073 Online Judge(字符串处理~)
Problem Description Ignatius is building an Online Judge, now he has worked out all the problems exc ...
随机推荐
- C#中有关字符串去重的解决方案
今天在群里看到一个同学的面试题 题目中有一个这样的要求 //本地有个文档文件a.txt里面包含的内容分为一段字符串"abacbacde"请编写一个程序,获取文件得到对应的内容,并对 ...
- [上传下载] C#FileUp文件上传类 (转载)
点击下载 FileUp.zip 主要功能如下 .把上传的文件转换为字节数组 .流转化为字节数组 .上传文件根据FileUpload控件上传 .把Byte流上传到指定目录并保存为文件 看下面代码吧 // ...
- 在.Net中进行跨线程的控件操作(上篇:Control.Invoke)
本文的重点在于介绍如何在多线程编程中,从非UI线程上访问界面中的控件.有过多线程编程经验的人都知道,当我们在非UI线程上试图给一个界面中的控件赋值的时候,比如说label的Text属性,系统会抛出一个 ...
- 优化有标量子查询的SQL
数据库环境:SQL SERVER 2008R2 今天在数据库中抓出一条比较耗费资源的SQL,只返回904条数据,居然跑了40多分钟.SQL及对应的数据量如下图: SELECT saft04.cur_y ...
- raw socket遇上windows
最近很长一段时间内又捡起了大学时丢下的网络协议,开始回顾网络协议编程,于是linux系统成了首选,它让我感到了无比的自由,可以很通透的游走于协议的各层. 最初写了个ARP欺骗程序,很成功的欺骗了win ...
- 使用UIBezierPath和CAShapeLayer画各种图形
转载自:http://www.cocoachina.com/ios/20160214/15251.html CAShapeLayer 是 CALayer 的子类,但是比 CALayer 更灵活,可以画 ...
- Linux 权限基础说明
1 权限位说明 Linux文件或目录的权限位是由个9个权限位来控制的,每三位为一组,它们分别是文件属主(owner/user)读.写.执行,用户组(Group)的读.写.执行以及(Other)其他 ...
- 使用APPLICATION制作缓存,转存一下,有一段写的还可以。
public sealed class CacheManager { private HttpApplicationState appPool = null; /// <summar ...
- WAMP(Windows+Apache+Mysql+PHP)环境搭建
学习PHP已经有一段时间,一直没有写过关于开发环境搭建的笔记,现在补上吧,因为安装配置的步骤记得不是很清楚,借鉴了一些别人的经验,总结如下: 首先去官方网站下载各个软件,下载需要的版本: Apache ...
- Linux 多用户和多用户边界
1. 需求背景 2. 多用户的边界: 独立的工作目录 3. 多用户的边界:可操作/访问的资源 4. 多用户的边界: 可执行的操作 5. 多用户的特性标识: UID和GID -------------- ...