1.2.2 Text_Reverse
Text Reverse
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
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.
- import java.util.Scanner;
- public class Main {
- static String reverseStr(String str){
- StringBuffer buf=new StringBuffer();
- buf.append(str);
- return buf.reverse().toString();
- }
- public static void main(String [] args){
- Scanner sc=new Scanner(System.in);
- int t=sc.nextInt();
- sc.nextLine();
- while(t-->0){
- String str1=sc.nextLine();
- String str[]=str1.split(" ");
- for(int i=0;i<str.length;i++){
- System.out.print(reverseStr(str[i]));
- if(i<str.length-1)
- System.out.print(" ");
- }
- if(str1.endsWith(" "))System.out.print(" "); ////尤其注意这里,表示最后一个字符后可能有空格
- System.out.println();
- }
- sc.close();
- }
- }
1.2.2 Text_Reverse的更多相关文章
随机推荐
- circRNA研究手册
环状RNA(circRNA)研究技术手册.doc.pdf (转自:汉恒生物)
- linux设置端口转发(一键设置)
linux设置端口转发 #下载rinetd程序并进入文件夹 wget http://www.boutell.com/rinetd/http/rinetd.tar.gz&&tar -xv ...
- MVC扩展Url.Action方法解决复杂对象参数问题
1:问题描述 @Url.Action("Index", "Home", new { Key = "Key", Val = new { Nam ...
- Spring boot实现监听Redis key失效事件实现和其它方式
需求: 处理订单过期自动取消,比如下单30分钟未支付自动更改订单状态 用户绑定隐私号码当订单结束取消绑定等 解决方案1: 可以利用redis自带的key自动过期机制,下单时将订单id写入redis,过 ...
- freemarker中对null值问题的处理
1. freemarker不支持null. 如果值为null会报错. 2.当值为null的处理 1)过滤不显示 Hello ${name!} 在属性后面加感叹号即可过滤null和空字符串 if和”?? ...
- 20170609批量生成WORD合同
Sub NextSeven_CodeFrame() Application.ScreenUpdating = False Application.DisplayAlerts = False Appli ...
- quick pow
#include<iostream> using namespace std; #define LL long long LL qpow(LL a,LL b,LL m) { LL r=1; ...
- dp练习(4)——过河卒
1010 过河卒 2002年NOIP全国联赛普及组 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 黄金 Gold 题解 题目描述 Description 如图,A ...
- Windows环境搭建ElasticSearch 5.*并配置head
前言: ES5*以上版本需要jdk1.8,jdk1.8,jdk1.8.重要的事情说三遍 1.下载ElasticSearch https://www.elastic.co/cn/downloads/el ...
- HDU 3720 深搜 枚举
DES:从23个队员中选出4—4—2—1共4种11人来组成比赛队伍.给出每个人对每个职位的能力值.给出m组人在一起时会产生的附加效果.问你整场比赛人员的能力和最高是多少. 用深搜暴力枚举每种类型的人选 ...