问题描述:

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. 《C专家编程》第一天

    1.2 C语言的早期体验 1)C语言的基本数据类型直接与底层硬件相对应.C语言不存在内置的复数类型.C语言一开始不支持浮点类型,直到硬件系统能够直接支持浮点数之后才增加了对它的支持. 2)auto关键 ...

  2. php parse_url 函数使用方法解析

    此函数返回一个关联数组,包含现有 URL 的各种组成部分.如果缺少了其中的某一个,则不会为这个组成部分创建数组项.组成部分为: scheme – 如 http host port pass path ...

  3. JavaScript数组的学习

    1数组的创建 var arr1 = new Array(); var arr2=[1,2,3]; 2数组常用的方法: push,pop,shift,unshift,splice,slice,sort, ...

  4. yii 自动生成的内容,分页信息(Displaying 1-10 of 15 results.)如何修改或是yii cgridview template summary

    问的白一点就是 Displaying 1-10 of 15 results 如何翻译 如果搜索的话, 搜这个会出来很多内容 yii cgridview template summary 好了,其他不说 ...

  5. yii [error] [exception.CHttpException.404] exception 'CHttpException' with message 'Unable to resolve the request "favicon.ico".'

    yii使用中,发现runtime文件夹下出现这个错误信息 解决办法:在生成的APP程序根目录下建.htaccess文件(前提是需要开启apache重写,具体如何开,查资料咯) 然后配置如下 <I ...

  6. css的clip裁剪

    clip 属性是用来设置元素的形状.用来剪裁绝对定位元素(absolute or fixed). clip有三种取值:auto |inherit|rect.inherit是继承,ie不支持这个属性, ...

  7. HDU3757

    题意:一些团队因为任务要去避难所,并且每个避难所必须要有团队在,避难所的数量小于等于团队的数量, 团队去避难所的消耗油量与路程成正比,求解最小耗油量.题目来源:2010 Northeastern Eu ...

  8. Lesson 3: The Amazing New Mobile Web

    Lesson 3: The Amazing New Mobile Web Article 1: This is Responsive by Brad Frost 各种响应式网站设计的资源. Artic ...

  9. OpenXml2.0 - 找不到类型或命名空间名称“DocumentFormat”

    在使用 OpenXml SDK2.0的过程中,很是郁闷的是总是报 '找不到类型或命名空间名称“SpreadsheetDocument”(是否缺少 using 指令或程序集引用?)'的错误,命名已经添加 ...

  10. Java中如何判断当前环境是大端字节顺序还是小端字节顺序

    Java非字节类型的基本类型,除了布尔型都是由组合在一起的几个字节组成的.这些数据类 型及其大小总结在表 2-1 中. 表:基本数据类型及其大小 数据类型 大小(以字节表示) Byte 1 Char ...