杭电acm1062 Text Reverse
来源:互联网 发布:防火知多少教案 编辑:程序博客网 时间:2024/06/17 14:15
Text Reverse
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 34449 Accepted Submission(s): 13532
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.
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
3olleh !dlrowm'I morf .udhI ekil .mca
Sample Output
hello world!I'm from hdu.I like acm.HintRemember to use getchar() to read '\n' after the interger T, then you may use gets() to read a line and process it.
//简单的字符串处理
/** * date:2017.11.12 * author:孟小德 * function:acm试题1062 * Text Reverse 文本倒置 */import java.util.*;public class acm1062{ public static void main(String[] args) { Scanner input = new Scanner(System.in); int num = input.nextInt(); input.nextLine(); String[] string = new String[num]; for (int i=0;i<num;i++) { string[i] = input.nextLine(); } String[] result = new String[num]; for (int i=0;i<num;i++) { String[] str = string[i].split(" "); //分割字符串 result[i] = stringReverse(str[0]); for (int j = 1;j<str.length;j++) { result[i] = result[i] + " " + stringReverse(str[j]); } //末尾空格加上 int n = string[i].length() - result[i].length(); for (int j = 0;j<n;j++) { result[i] += " "; } } for (int i = 0;i<num;i++) { System.out.println(result[i]); } } //翻转单词字母 public static String stringReverse(String str) { if (str.equals("")) { return ""; } else { String string = String.valueOf(str.charAt(str.length()-1)); for (int i=str.length()-2;i>=0;i--) { string += String.valueOf(str.charAt(i)); } return string; } }}
阅读全文
0 0
- 杭电acm1062 Text Reverse
- 杭电1062-Text Reverse
- 杭电1062 Text Reverse
- 【杭电】[1062]Text Reverse
- 杭电OJ1062 Text Reverse
- 杭电OJ1062-Text Reverse
- Text Reverse(杭电oj1062)
- 杭电 HDU 1062 Text Reverse
- 杭电ACM 1062: Text Reverse
- 杭电 hdu 1062 Text Reverse
- 杭电1062 之 Text Reverse
- 杭电ACM 1062: Text Reverse
- 杭电ACM1321——Reverse Text~~逆序输出字符串
- 杭电1062(Text Reverse)字符串翻转问题
- 杭电acm刷题(3):1062,Text Reverse
- 杭电acmText Reverse
- 杭电acm1062Text Reverse
- Reverse Text
- Linux多线程Pthread学习小结
- textview加载报错android.view.InflateException: Binary XML file line #0: Error inflating class TextView
- 在vue项目创建的后开发中发现This dependency was not found: * !!vue-style-loader!css-loader?{"minimize":false,"
- Android学习之路
- delphi_基于RichEdit的简易文本编辑器
- 杭电acm1062 Text Reverse
- 文本情感分类(三):到底需不需要分词
- 电力公司的业务主站如何控制用户的智能电表启停
- 树状数组整理
- OpenStack历史知识
- JSON 与 对象 、集合 之间的转换
- Caused by: org.hibernate.exception.SQLGrammarException: could not extract ResultSet 报错原因
- 安卓点击加减号实现数字加减功能
- eclipse配置tomcat