国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁(yè) > 學(xué)院 > 開(kāi)發(fā)設(shè)計(jì) > 正文

Hdu 1062

2019-11-11 00:16:45
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友

Text Reverse

Time Limit: 2000/1000 MS (java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 29094 Accepted Submission(s): 11433

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.

題解:字符串反串,可以運(yùn)用棧原理。

import java.util.Scanner;public class Main { public static String revert(String s){ String res = ""; char[] s1 = s.toCharArray(); for(int i=s1.length-1;i>=0;i--){ res+=s1[i]; }// System.out.println(res); return res; } public static void main(String[] args) { Scanner in = new Scanner(System.in); int N = in.nextInt(); in.nextLine(); while(N-- > 0){ String str = in.nextLine();// System.out.println(str.length()); //字符串處理 String[]strs = str.split(" "); String res = "";// System.out.println("length"+strs.length); for(int i=0;i<strs.length;i++){ if(i==strs.length-1) res += revert(strs[i]); else res += revert(strs[i]) + " "; } if(str.endsWith(" ")) res += " ";//Java代碼需要考慮這種情況,不然提交PE。 //PE后反思了一下發(fā)現(xiàn)還是自己寫(xiě)的方法靠譜一些,處理出的東西不是雜七雜八的 System.out.println(res); } }}

這是我自己沒(méi)用Java庫(kù)提供的方法處理字符串,居然簡(jiǎn)潔的不得了,只有20多行代碼,啊哈哈,而且一次AC

import java.util.Scanner;public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); int N = in.nextInt(); in.nextLine(); while(N-- > 0){ String str = in.nextLine(); //字符串處理 String res = ""; String res1 = ""; for(int i=0;i<str.length();i++){ if(str.charAt(i) == ' '){ res += res1; res += str.charAt(i); res1 = ""; }else{ res1 = str.charAt(i) + res1; } } res += res1; System.out.println(res); } }}
發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 嘉荫县| 大石桥市| 连南| 达孜县| 东安县| 汝城县| 忻州市| 双江| 都兰县| 株洲市| 渑池县| 泸西县| 沙洋县| 陵川县| 奉新县| 镇原县| 噶尔县| 鹤峰县| 建始县| 肇州县| 湖州市| 乌兰浩特市| 泰宁县| 阿拉尔市| 昌吉市| 平安县| 巩留县| 南和县| 盐池县| 江永县| 宾川县| 西乌珠穆沁旗| 谢通门县| 长治县| 大城县| 赣州市| 临夏县| 陈巴尔虎旗| 灵川县| 冀州市| 瑞丽市|