微软实习生第一题
来源:互联网 发布:佣金宝交易软件 编辑:程序博客网 时间:2024/05/18 02:49
/*时间限制:10000ms单点时限:1000ms内存限制:256MBFor 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).InputInput consists of multiple cases, one case per line. Each case is one string consisting of ASCII characters.OutputFor each case, print exactly one line with the reordered string based on the criteria above.样例输入aabbccdd007799aabbccddeeff113355zz1234.89898abcdefabcdefabcdefaaaaaaaaaaaaaabbbbbbbddddddee样例输出abcdabcd013579abcdefz013579abcdefz<invalid input string>abcdefabcdefabcdefabdeabdeabdabdabdabdabaaaaaaa*/
#include <stdio.h>#include<string.h>#define Length_MAX 500000char input[Length_MAX];int count[36] = {0};//清空数组int count[36]void clear_count(){int i = 0;for(i = 0; i < 36; i++){count[i] = 0;}}//判断int count[36]数组中存储的所有元素之和是否为0int isOver(){int sum = 0;int i = 0;for(i = 0; i < 36; i++){sum = sum + count[i];}return sum;}/**参数:str[]为字符串数字,length为该字符串数组的长度(包括'\0')*返回值:如果str[]为有效字符串(只包含0-9或者a-z),则返回1,无效字符串则返回0.*功能:统计str[]字符串数组中各个字符的数量,并存储到数组int count[36]中,count[0-9]分别对应字符'0'到'9'*的数量, count[10-36]分别对应字符'a'-'z'的数量*/int init_Count(char str[], int length){int i = 0;int pos = 0;for(i = 0; i < length; i++){if(str[i] >= '0' && str[i] <= '9'){pos = (int)(str[i] - '0');count[pos]++;}else if(str[i] >= 'a' && str[i] <= 'z'){pos = (int)(str[i] - 'a') + 10;count[pos]++;}else{return 0;}}return 1;}int main(){int i = 0;int j = 0;int length = 1; int valid = 0;gets(input);for(i = 0; i < length; i++){valid = init_Count(input, strlen(input));if(valid ==0){printf("<invalid input string>\n");}else{char temp = '0';while(isOver() != 0){for(j = 0; j < 36; j++){if(count[j] > 0){if(j>= 0 && j <=9){temp = (char)('0'+j);printf("%c", temp);}else{temp = (char)('a'+j-10);printf("%c", temp);}count[j]--;}}}printf("\n");}clear_count();}}
6 0
- 微软实习生第一题
- 微软2016实习生笔试--第一题Font Size
- 微软2014实习生及秋令营技术类职位在线测试(第一题)
- 微软2014实习生及秋令营技术类职位在线测试第一题:String reorder
- 微软2016年4月实习生笔试第一题-font size题解
- 2012微软暑期实习生笔试题
- 2012微软暑期实习生笔试题
- 微软2013暑假实习生笔试题
- 微软2013暑期实习生笔试题错误
- 微软2013暑假实习生笔试题
- 微软2013暑假实习生笔试题
- 2013.04微软暑期实习生招聘笔试题
- 微软Microsoft 2013暑假实习生笔试题
- 2014微软实习生招聘第二题
- 微软2014实习生在线测试题
- 2014微软实习生笔试题-String reorder
- 微软实习生要求
- 微软实习生笔试
- 三个数的排序
- 分治法(归并排序、快速排序)
- rman backup scripts
- 什么是web
- c++ 的前世今生
- 微软实习生第一题
- override 与overload 的区别
- Summation of Four Primes - PC110705
- 《C++ 沉思录》阅读笔记——句柄类
- pushScene,popScene,replaceScen切换场景之间的区别
- [LeetCode] ZigZag Conversion
- WebService学习(一)
- Ubuntu环境下配置J2EE开发环境jdk+tomcat+mysql+myeclipse
- 数位 dp HDU 2089 不要62