微软2014年在线笔试题前两题
来源:互联网 发布:青海干部网络教育平台 编辑:程序博客网 时间:2024/06/05 15:16
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 “” 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.
样例输入
aabbccdd
007799aabbccddeeff113355zz
1234.89898
abcdefabcdefabcdefaaaaaaaaaaaaaabbbbbbbddddddee
样例输出
abcdabcd
013579abcdefz013579abcdefz
abcdefabcdefabcdefabdeabdeabdabdabdabdabaaaaaaa
我只实现了要求一,后面的还要再想想
#include <iostream>#include <string>using namespace std;extern int max1=0;void f(string s,int hash[]){ int i,t; //将输入的字符存到hash数组其ASCII码对应的下标下,同时标记重复字符的最大值 for(i= 0;i<s.size();i++) { t=int(s[i]); hash[t]++; if(hash[t]>max1) max1=hash[t]; }}int _tmain(int argc, _TCHAR* argv[]){ string s; cout<<"Input:"<<endl; char c; getline(cin,s); int hash[200]={}; f(s,hash); //遍历hash数组 while(max1) { int i=0; for(i;i<200;i++) { if(hash[i]!=0) { if(hash[i]==max1) { max1--; } c=(char)i; cout<<c; hash[i]--; } } } getchar(); getchar(); return 0;}
- 微软2014年在线笔试题前两题
- 微软2014在线笔试 第三题
- 微软在线笔试题2015
- 微软在线笔试题:FontSize
- 微软2014在线笔试第一题 简便易懂算法
- K-th string微软2014在线笔试题
- 2016年微软在线笔试题之Font Size
- 微软2014年笔试题
- 微软在线笔试第一题 复杂算法
- 2015.4.3微软在线笔试第二题
- 微软2014笔试
- 微软2014笔试
- 高效解决 2.K-th string (微软2014在线笔试,第二题)
- 2016年4月微软在线笔试第二题-403 forbidden
- 微软2016年实习生在线笔试第二题(403 Forbidden)
- 微软2017年预科生计划在线编程笔试 题目1 : Legendary Items
- 微软2017年预科生计划在线编程笔试题Legendary Items
- 微软2017年预科生计划在线编程笔试_上
- 对话框嵌入到对话框 或者:窗口嵌入到窗口,一个窗口嵌入到另一个窗口
- linux下mysql日常用法
- JSP结合JXL.jar包实现网页Table显示读取到的Excel表格
- android 自定义VIew 动态在页面中改变页面的布局
- hdu2673 sort水题,一遍过
- 微软2014年在线笔试题前两题
- android EditText控件修改默认选中事件
- POJ 2299 Ultra-QuickSort(逆序数 树状数组)
- 数据库调优教程汇总
- android开发环境安装
- 了解Cocos2d-x整个引擎框架——helloworld
- 做个只有登录功能的系统
- Ajax的初步认识和封装
- Linux下which、whereis、locate、find 命令的区别