问题描述:

Time Limit: 10000ms
Case Time Limit: 1000ms
Memory Limit: 256MB

Description
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
Input consists of multiple cases, one case per line. Each case is one string consisting of ASCII characters.

Output
For each case, print exactly one line with the reordered string based on the criteria above.

Sample In
aabbccdd
007799aabbccddeeff113355zz
1234.89898
abcdefabcdefabcdefaaaaaaaaaaaaaabbbbbbbddddddee

Sample Out
abcdabcd
013579abcdefz013579abcdefz
<invalid input string>
abcdefabcdefabcdefabdeabdeabdabdabdabdabaaaaaaa

思路:用数组的位置表示每个字符出现的次数,再打印!

public class test5 {

    public static void main(String[] args) {

        String aString="abcdefabcdefabcdefaaaaaaaaaaaaaabbbbbbbddddddee";
char b[]=aString.toCharArray();
aa(b);
} public static void aa(char str[]) {
int []count=new int[35];
for (int i = 0; i < str.length; i++) { if (str[i]<='9' && str[i]>='0') {
count[str[i]-'0']++;
}
else if (str[i]<='z'&& str[i]>='a') {
count[str[i]-'a'+10]++;
}
else {
System.out.println("非法");
}
} while (!count.equals(0)) { for (int j = 0; j < count.length; j++) {
if (count[j]>0) { if (j<10) {
int y=j+'0';
char x = (char)y;
System.out.print(x+" ");
count[j]--;
}
else {
int y=j+'a'-10;
char x = (char)y;
System.out.print(x+" ");
count[j]--;
}
}
}
}
}
}

  

最新文章

  1. 解决window2012 IIS8 配置的网站无法下载exe文件的问题
  2. [HIve - LanguageManual] Sort/Distribute/Cluster/Order By
  3. div 块跟随 鼠标点击
  4. MFC_Office
  5. linux date -d 的一些使用方法
  6. 【JS控制图片显示的大小(图片等比例缩放)】
  7. P177 test 6-3 UVa536
  8. Swing入门
  9. 带你走进SAP项目实施过程——立项(1)
  10. mdb导入SqlServer
  11. 计蒜客NOIP2017提高组模拟赛(五)day1-机智的 AmyZhi
  12. 初学pyhon的几个练习小程序
  13. Vysor破解助手for Linux and macOS
  14. IDEA项目搭建十四——Web站点Controller基类及布局页静态资源设计
  15. 浅析data:image/png;base64的应用
  16. CLOB数据类型截取SUBSTR_按开始位置偏移量
  17. 安卓开发_浅谈Action Bar
  18. JAVA之字母与相对应数字转换
  19. Mybatis 使用 mapper 接口规范的 一对一, 一对多,多对多映射
  20. 使用Jmeter对API进行性能测试

热门文章

  1. [转] JSON for java入门总结
  2. 头像上传ASP.NET MVC实现-可拖动大小实时预览
  3. DataTable操作工具类DataTableHelper
  4. Android 网络编程与通信协议
  5. 让 IE 支持HTML5 placeholder
  6. MySql中的时间类型datetime,timestamp,date,year比较
  7. vs2013+sql server2012 +win8.1+entity framework + linq
  8. java事件处理
  9. 为什么要刷新一下才能获取cookie
  10. EDIT编辑框