微软2014实习生及校招秋令营技术类职位,在线编程题目及解答。

题目1 : String reorder

时间限制:10000ms

单点时限:1000ms

内存限制: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.

样例输入aabbccdd007799aabbccddeeff113355zz1234.89898abcdefabcdefabcdefaaaaaaaaaaaaaabbbbbbbddddddee样例输出abcdabcd013579abcdefz013579abcdefzabcdefabcdefabcdefabdeabdeabdabdabdabdabaaaaaaa

题目解答:

#include <iostream>#include <String>using namespace std;void reorder(string input);void main(){string input;while(cin >> input){reorder(input);}}void reorder(string input){int *ptiShowTimes = new int[36]();int finishFlag = true;//统计每一个字母出现的次数for (int i = 0; i < input.length(); i++){if ((input[i] < '0') || (input[i] > 'z') || ((input[i] > '9') && (input[i] < 'a'))){cout << "<invalid input string>" << endl;return;}if ((input[i] >= '0') && (input[i] <= '9')){ptiShowTimes[input[i]-'0']++;}else{ptiShowTimes[input[i]-'a'+10]++;}}do{finishFlag = true;for (int i = 0; i < 36; i++){if (0 != ptiShowTimes[i]){finishFlag = false;if (i < 10){cout << (char)(i + '0');ptiShowTimes[i]–;}else{cout << (char)('a' + i – 10);ptiShowTimes[i]–;}}}}while (!finishFlag);cout << endl;}

题目2 : K-th string

时间限制:10000ms

单点时限:1000ms

内存限制:256MB

Description

Consider a string set that each of them consists of {0, 1} only. All strings in the set have the same number of 0s and 1s. Write a program to find and output the K-th string according to the dictionary order. If such a string doesn’t exist, or the input is not valid, please output “Impossible”. For example, if we have two ‘0’s and two ‘1’s, we will have a set with 6 different strings, {0011, 0101, 0110, 1001, 1010, 1100}, and the 4th string is 1001.

Input

The first line of the input file contains a single integer t (1 ≤ t ≤ 10000), the number of test cases, followed by the input data for each test case.Each test case is 3 integers separated by blank space: N, M(2 <= N + M <= 33 and N , M >= 0), K(1 <= K <= 1000000000). N stands for the number of ‘0’s, M stands for the number of ‘1’s, and K stands for the K-th of string in the set that needs to be printed as output.

Output

For each case, print exactly one line. If the string exists, please print it, otherwise print “Impossible”.

样例输入32 2 22 2 74 7 47样例输出0101Impossible01010111011

题目解答:

#include <iostream>#include <String>using namespace std;void reorder(string input);void main(){string input;while(cin >> input){reorder(input);}}void reorder(string input){int *ptiShowTimes = new int[36]();int finishFlag = true;//统计每一个字母出现的次数for (int i = 0; i < input.length(); i++){if ((input[i] < '0') || (input[i] > 'z') || ((input[i] > '9') && (input[i] < 'a'))){cout << "<invalid input string>" << endl;return;}if ((input[i] >= '0') && (input[i] <= '9')){ptiShowTimes[input[i]-'0']++;}else{ptiShowTimes[input[i]-'a'+10]++;}}do{finishFlag = true;for (int i = 0; i < 36; i++){if (0 != ptiShowTimes[i]){finishFlag = false;if (i < 10){cout << (char)(i + '0');ptiShowTimes[i]–;}else{cout << (char)('a' + i – 10);ptiShowTimes[i]–;}}}}while (!finishFlag);cout << endl;}

题目3 : Reduce inversion count

时间限制:10000ms

单点时限:1000ms

内存限制:256MB

Description不要识途去改变他人,同样,也不要被他人所改变。改了,就不是自己了。

微软2014实习生及校招秋令营技术类职位,在线编程题目及解答。

相关文章:

你感兴趣的文章:

标签云: