string reorder
来源:互联网 发布:淘宝店铺头像去哪改 编辑:程序博客网 时间:2024/05/21 08:59
Time Limit: 10000ms
Case Time Limit: 1000ms
Memory Limit: 256MB
For this question, your program is required to process an input string containing only ASCII characters between ‘0’ and ‘9’, or between ‘a’ and ‘z’ (including ‘0’, ‘9’, ‘a’, ‘z’).
Your program should reorder and split all input string characters into multiple segments, and output all segments as one concatenated string. The following requirements should also be met,
1. Characters in each segment should be in strictly increasing order. For ordering, ‘9’ is larger than ‘0’, ‘a’ is larger than ‘9’, and ‘z’ is larger than ‘a’ (basically following ASCII character order).
2. Characters in the second segment must be the same as or a subset of the first segment; and every following segment must be the same as or a subset of its previous segment.
Your program should output string “<invalid input string>” when the input contains any invalid characters (i.e., outside the '0'-'9' and 'a'-'z' range).
Sample In
aabbccdd
007799aabbccddeeff113355zz
1234.89898
abcdefabcdefabcdefaaaaaaaaaaaaaabbbbbbbddddddee
Sample Out
abcdabcd
013579abcdefz013579abcdefz
<invalid input string>
Case Time Limit: 1000ms
Memory Limit: 256MB
For this question, your program is required to process an input string containing only ASCII characters between ‘0’ and ‘9’, or between ‘a’ and ‘z’ (including ‘0’, ‘9’, ‘a’, ‘z’).
Your program should reorder and split all input string characters into multiple segments, and output all segments as one concatenated string. The following requirements should also be met,
1. Characters in each segment should be in strictly increasing order. For ordering, ‘9’ is larger than ‘0’, ‘a’ is larger than ‘9’, and ‘z’ is larger than ‘a’ (basically following ASCII character order).
2. Characters in the second segment must be the same as or a subset of the first segment; and every following segment must be the same as or a subset of its previous segment.
Your program should output string “<invalid input string>” when the input contains any invalid characters (i.e., outside the '0'-'9' and 'a'-'z' range).
Input
Output
Sample In
aabbccdd
007799aabbccddeeff113355zz
1234.89898
abcdefabcdefabcdefaaaaaaaaaaaaaabbbbbbbddddddee
Sample Out
abcdabcd
013579abcdefz013579abcdefz
<invalid input string>
abcdefabcdefabcdefabdeabdeabdabdabdabdabaaaaaaa
import java.util.ArrayList;import java.util.List;import java.util.Scanner;public class Main {public static void main(String[] args) {Scanner in = new Scanner(System.in);List<String> stringList = new ArrayList<String>();for (int i = 0; i < 4; i++) {stringList.add(in.nextLine());}System.out.println("================");for (String string : stringList) {for (int i = 0; i < string.length(); i++) {if (!((string.charAt(i) >= '0' && string.charAt(i) <= '9') || (string.charAt(i) >= 'a' && string.charAt(i) <= 'z'))) {System.out.println("<invalid input string>");break;}if (i == string.length() - 1) {process(string);}}}}private static void process(String string) {//System.out.println("after: " + sort(string));String sortedString = sort(string);List<Character> charList = new ArrayList<Character>();List<Character> deleteCharList = new ArrayList<Character>();for (int i = 0; i < sortedString.length(); i++) {char ch = sortedString.charAt(i);charList.add(ch);}while (!charList.isEmpty()) {List<Character> newCharList = new ArrayList<Character>();for (Character ch : charList) {if (!newCharList.contains(ch)) {newCharList.add(ch);}}//printList(newCharList);deleteCharList.addAll(newCharList);for (Character character : newCharList) {charList.remove(character);}//printList(charList);}printList(deleteCharList);}private static void swap(char[] chars, int a, int b) {char temp = chars[a];chars[a] = chars[b];chars[b] = temp;}private static String sort(String string) {char[] chars = string.toCharArray();for (int i = 0; i < chars.length - 1; i++) {for (int j = i + 1; j < chars.length; j++) {if (chars[j] < chars[i]) {swap(chars, i, j);}}}return new String(chars);}private static void printList(List<Character> list) {for (Character character : list) {System.out.print(character);}System.out.println();}}
0 0
- String reorder
- string reorder
- String reorder
- String reorder
- 题目1 : String reorder
- 练习 题目1 : String reorder
- 【微软2014实习生】 String reorder
- 2014微软在线测试-String reorder-WA
- String reorder(一道自定义排序题)
- 2014微软实习生笔试题-String reorder
- 微软2014校招笔试题-String reorder
- 微软2014实习生招聘编程测试string reorder
- 微软实习机试题 String reorder 的 Java 实现
- 微软2014实习生在线测试之String reorder
- 微软2014实习生及秋令营之String reorder问题
- (2014微软实习生笔试题)1.String reorder
- 微软2014实习生在线测试之String reorder .
- 微软实习生测试题题目1 : String reorder
- 《编写高质量代码——Web前端开发修炼之道》读后随笔
- JavaScript开发规范要求
- 黑马程序员 —— Java高级视频_IO输入与输出(第十八天)2
- 【算法基础】冒泡、选择、插入排序(三种基本排序)
- Intent的几种用法
- string reorder
- Android 页面布局属性全
- Linux下查看文件和文件夹大小的df和du命令
- redis启动和关闭
- 物化视图在物流系统中的应用
- C# 10点半扑克牌游戏程式码
- Google Protocol Buffer持久化框架分析
- Memcached Redis Membase性能测试对比分析
- DBMS_STATS分析表 (zt) dbms_stats.set_table_stats 手工设置统计信息