问题描述:

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

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

  1. public class test5 {
  2.  
  3. public static void main(String[] args) {
  4.  
  5. String aString="abcdefabcdefabcdefaaaaaaaaaaaaaabbbbbbbddddddee";
  6. char b[]=aString.toCharArray();
  7. aa(b);
  8. }
  9.  
  10. public static void aa(char str[]) {
  11. int []count=new int[35];
  12. for (int i = 0; i < str.length; i++) {
  13.  
  14. if (str[i]<='9' && str[i]>='0') {
  15. count[str[i]-'0']++;
  16. }
  17. else if (str[i]<='z'&& str[i]>='a') {
  18. count[str[i]-'a'+10]++;
  19. }
  20. else {
  21. System.out.println("非法");
  22. }
  23. }
  24.  
  25. while (!count.equals(0)) {
  26.  
  27. for (int j = 0; j < count.length; j++) {
  28. if (count[j]>0) {
  29.  
  30. if (j<10) {
  31. int y=j+'0';
  32. char x = (char)y;
  33. System.out.print(x+" ");
  34. count[j]--;
  35. }
  36. else {
  37. int y=j+'a'-10;
  38. char x = (char)y;
  39. System.out.print(x+" ");
  40. count[j]--;
  41. }
  42. }
  43. }
  44. }
    }
  45. }

  

微软在线测试题String reorder的更多相关文章

  1. 微软2014实习生及秋令营技术类职位在线测试(题目1 : String reorder)

    题目1 : String reorder 时间限制:10000ms 单点时限:1000ms 内存限制:256MB Description For this question, your program ...

  2. Windows10微软在线账户与本地账户的切换方法

    Win10里面存在着两个账户,除了本地账户外,还有着一个微软在线账户,这个账户可以同步设置.日历等数据.不过对于大部分用户来说,本地账户已经足够我们使用了,那么这两个账户之间该如何切换呢? Win10 ...

  3. 微软在线实验室启用谷歌的reCAPTCHA,我们又丢失了一个好东东

    在没有启用reCAPTCHA的日子,我们可以在微软的在线实验室www.microsoft.com/handsonlabs 中找到许许多多的文档.视频.动手实验环境. 不需要任何硬件.技术,就可以快速的 ...

  4. Win Server 8中的利器:微软在线备份服务

    微软在Windows Server 8中添加在线备份服务了?你一定以为我在开玩笑,是吧?但是微软确实这么做了.     微软在Windows Server 8中添加在线备份服务了?你一定以为我在开玩笑 ...

  5. 微软2014校招笔试题-String reorder

    Time Limit:10000ms Case Time Limit:1000ms Memory Limit:256MB Description For this question, your pro ...

  6. 微软在线测试之lucky string,有关斐波那契的题目都在此了

    解决方案: int _tmain(int argc,_TCHAR* argv[]) { size_t fib[] = {1,2,3,5,8,13,21,34}; string str,tempstr; ...

  7. String reorder

    本问题出自:微软2014实习生及秋令营技术类职位在线测试 (Microsoft Online Test for Core Technical Positions) Description For th ...

  8. 微软在线 VSTS/TFS 使用简介,如何删除项目,帐号,获取git地址等

    名称:微软 VSTS 全称: Visual Studio Team Services 地址:https://www.visualstudio.com/zh-hans/ 说明:注册就可以了使用了(如何使 ...

  9. [微软实习生2014]K-th string

    很久之前的事情了,微软2014实习生的在线测试题,记录下来以备后用. 题目描述: Description Consider a string set that each of them consist ...

随机推荐

  1. Injecting and Binding Objects to Spring MVC Controllers--转

    I have written two previous posts on how to inject custom, non Spring specific objects into the requ ...

  2. Memcached应用总结

    Memcached应用总结 memcached是一款高性能的分布式缓存系统,凭借其简单方便的操作,稳定可靠的性能广泛应用于互联网应用中,网上关于memcached介绍的资料也很多,最经典的资料就是&l ...

  3. linux下软件安装与卸载

    linux上软件二进制安装主要分为:rpm手动安装和yum在线安装(其所安装的都为rpm二进制包). 关于rpm手动安装,学习后面内容前需分清如下内容: 包全名 : 操作的包是没有安装的软件包时,使用 ...

  4. 关于oracle dbms_job 定时执行的内容。

    一.设置初始化参数 job_queue_processessql> alter system set job_queue_processes=n;(n>0)job_queue_proces ...

  5. Windows8 正式版最简单的去除桌面水印方法

    方法一: 优点:无需替换文件,无需任何工具,对系统没有副作用缺点:更换主题或者壁纸之后水印再现方法:按住 “win键+P” 进入 “第二屏幕 ”选择 “扩展”再按住 “win键+P” 进入 “第二屏幕 ...

  6. 最全的ORACLE-SQL笔记

    -- 首先,以超级管理员的身份登录oracle sqlplus sys/bjsxt as sysdba --然后,解除对scott用户的锁 alter user scott account unloc ...

  7. PHP HTTP

    安装 HTTP 函数是 PHP 核心的组成部分.无需安装即可使用这些函数. PHP HTTP 函数 PHP:指示支持该函数的最早的 PHP 版本. 函数 描述 PHP header() 向客户端发送原 ...

  8. 摘抄官方文档: spring boot配置 iframe同源可访问

    使用java配置,跟spring security配置在一起 @EnableWebSecurity public class WebSecurityConfig extends WebSecurity ...

  9. vimtutor-summary

  10. 【Ecstore2.0】计划任务/队列/导入导出 的执行问题

    [环境]CENTOS6.3 + wdcp(php5.3) [症状]可正常加入队列,但不执行队列 [原因]大部份都是用户权限造成 [原理] Ecstore2.0的导入导出.发送邮件.日常清理备份等任务操 ...