问题描述:

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]--;
}
}
}
}
}
}

  

微软在线测试题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. Nginx优化—配置优化

    完整配置如下所示: user nginx; #运行的用户 pid /var/run/nginx.pid; worker_processes auto; #定义了nginx对外提供web服务时的word ...

  2. C#第一节课

    1,命名规范 A.如果声明一个变量,小写,如果有多个单词,后面首字母大写 如: string sString="aa"; int iNum=20; bool bMale=false ...

  3. ajax请求在ie8下缓存问题

    我今天在改项目bug的时候,发现ajax请求在ie8下有缓存,在缓存过期之前,针对相同地址发起的多个Ajax请求,只有第一次会真正发送到服务端.在某些情况下,这种默认的缓存机制并不是我们希望的(比如获 ...

  4. springMVC如何判断入参是默认参数还是请求传过来的参数?

    springMVC如何判断入参是默认参数还是请求传过来的参数?

  5. java获取字符串格式日期向前或向后n天的日期

    private void setTilteMessage(){          BaseDao dao = new BaseDao();          String titleData = da ...

  6. VM下Linux网卡丢失(pcnet32 device eth0 does not seem to be ...)解决方案

    系统启动日志:Bringing up interface eth0: pcnet32 device eth0 does not seepresent, delaying initialization. ...

  7. MySQL命令mysqldump参数大全

    参数参数说明--all-databases  , -A导出全部数据库.mysqldump  -uroot -p --all-databases--all-tablespaces  , -Y导出全部表空 ...

  8. JavaScript forEach方法

    最近看了一些html5和js方面的书,受益匪浅,因为看的东西比较多,却都没有怎么静心来做整理,慢慢来吧,可能最近自己有点儿小紧张.今天跟大家分享下JavaScript的forEach方法(其实是从&l ...

  9. @NotNull丶@NotBlank丶@NotEmpty

    1.@NotNull:不能为 Null,但是可以为Empty:用在基本数据类型上. @NotNull(message="{state.notnull.valid}", groups ...

  10. Linux定时任务命令crontab

    作为一个php码农,linux接触总是很少,但又是必须会的一项技能,今天学到的linux命令是crontab命令. 注:以下总结基于Ubuntu 12.04 去/etc目录下看看 先去Ubuntu的/ ...