微软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.

样例输入
aabbccdd
007799aabbccddeeff113355zz
1234.89898
abcdefabcdefabcdefaaaaaaaaaaaaaabbbbbbbddddddee
样例输出
abcdabcd
013579abcdefz013579abcdefz
&lt;invalid input string&gt;
abcdefabcdefabcdefabdeabdeabdabdabdabdabaaaaaaa

题目解答:

#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”.
样例输入
3
2 2 2
2 2 7
4 7 47
样例输出
0101
Impossible
01010111011

题目解答:

#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

Find a pair in an integer array that swapping them would maximally decrease the inversion count of the array. If such a pair exists, return the new inversion count; otherwise returns the original inversion count. Definition of Inversion: Let (A[0], A[1] ... A[n], n <= 50) be a sequence of n numbers. If i < j and A[i] > A[j], then the pair (i, j) is called inversion of A. Example: Count(Inversion({3, 1, 2})) = Count({3, 1}, {3, 2}) = 2 InversionCountOfSwap({3, 1, 2})=> {  InversionCount({1, 3, 2}) = 1 <-- swapping 1 with 3, decreases inversion count by 1  InversionCount({2, 1, 3}) = 1 <-- swapping 2 with 3, decreases inversion count by 1  InversionCount({3, 2, 1}) = 3 <-- swapping 1 with 2 , increases inversion count by 1 }

Input

Input consists of multiple cases, one case per line.Each case consists of a sequence of integers separated by comma.

Output

For each case, print exactly one line with the new inversion count or the original inversion count if it cannot be reduced.
样例输入
3,1,2
1,2,3,4,5
样例输出
1
0

题目解答:

#include <sstream>
#include <vector>
#include <map>
#include <stdlib.h>
#include <iostream>
#include <algorithm>

using namespace std;
int calInversionCount(vector<int>::iterator begin, int *ptrSmallerNum, int *ptrBiggerNum, int dataLen);
int getMostInversionCount(int *ptrSmallerNum, int dataLen);

void main()
{
	int dataLen = 0;
	string str = "";
	while (getline(cin, str))
	{
		vector<int> data;
		stringstream ss(str);
		string tmp;
		while (getline(ss, tmp, ','))
			data.push_back(atoi(tmp.c_str()));

		dataLen = data.size();

		//申请两个数组,用于存放小于它的个数和大于它的个数
		int *ptrBiggerNum = new int[dataLen]();
		int *ptrSmallerNum = new int[dataLen]();

		//计算出每一个元素小于它的个数和大于它的个数
		int inversionOldCount = calInversionCount(data.begin(), ptrSmallerNum, ptrBiggerNum, dataLen);

		//获得inversionCount个数最大的元素
		int iMostInverCountIndex = getMostInversionCount(ptrSmallerNum, dataLen);

		//获得比其他元素小最多次数的元素
		int iSmallestInverCountIndex = getMostInversionCount(ptrBiggerNum, dataLen);

		//将上述两个元素进行交换
		swap(data[iMostInverCountIndex], data[iSmallestInverCountIndex]);

		//计算新的inversioncount
		int inversionNewCount = calInversionCount(data.begin(), ptrSmallerNum, ptrBiggerNum, dataLen);

		if (inversionNewCount < inversionOldCount)
		{
			cout << inversionNewCount << endl;
		}
		else
		{
			cout << inversionOldCount << endl;
		}

		delete[] ptrBiggerNum;
		delete[] ptrSmallerNum;
	}

}

int getMostInversionCount(int *ptrSmallerNum, int dataLen)
{
	int iMostInversionCount = ptrSmallerNum[0];
	int i = 0;
	int result = 0;
	for (; i < dataLen; i++ )
	{
		if (ptrSmallerNum[i] >= iMostInversionCount)
		{
			iMostInversionCount = ptrSmallerNum[i];
			result = i;
		}
	}
	return result;
}

int calInversionCount(vector<int>::iterator begin, int *ptrSmallerNum, int *ptrBiggerNum, int dataLen)
{
	int inversionCount = 0;

	int i = 0;
	int j = 0;

	for (; i < dataLen; i++)
	{
		for (j = i + 1; j < dataLen; j++)
		{
			if (*(begin+j) < *(begin+i))
			{
				//统计出每一个成员的小于它的数和大于它的数
				ptrSmallerNum[i]++;
				ptrBiggerNum[j]++;
				inversionCount++;
			}
		}
	}
	return inversionCount;
}

题目4 : Most Frequent Logs

时间限制:10000ms 单点时限:3000ms 内存限制:256MB

Description

In a running system, there are many logs produced within a short period of time, we‘d like to know the count of the most frequent logs. Logs are produced by a few non-empty format strings, the number of logs is N(1<=N<=20000), the maximum length of each log is 256. Here we consider a log same with another when their edit distance (see note) is <= 5. Also we have a) logs are all the same with each other produced by a certain format string b) format strings have edit distance  5 of each other. Your program will be dealing with lots of logs, so please try to keep the time cost close to O(nl), where n is the number of logs, and l is the average log length. Note edit distance is the minimum number of operations (insertdeletereplace a character) required to transform one string into the other, please refer to http://en.wikipedia.org/wiki/Edit_distance for more details.

Input

Multiple lines of non-empty strings.

Output

The count of the most frequent logs.
样例输入
Logging started for id:1
Module ABC has completed its job
Module XYZ has completed its job
Logging started for id:10
Module ? has completed its job
样例输出
3

题目解答:

做不动了,后面有解答的时候再补上吧!

时间: 2024-10-14 06:25:37

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

【微软2014实习生及秋令营技术类职位在线测试】题目3 : Reduce inversion count

时间限制:10000ms 单点时限:1000ms 内存限制:256MB Description Find a pair in an integer array that swapping them would maximally decrease the inversion count of the array. If such a pair exists, return the new inversion count; otherwise returns the original invers

【微软2014实习生及秋令营技术类职位在线測试】题目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

微软2014实习生在线测试之K-th string

问题描述: Time Limit: 10000msCase Time Limit: 1000msMemory Limit: 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 str

【转载】2014 IT公司校招应届生待遇大揭秘

2014 IT公司校招应届生待遇大揭秘 公司名称        职位类别        待遇(校招年份) 百度                  开发类                13K*14.6 + 800饭补(400+20*20) (2014) (注:今年百度相对比较多的人拿了special)                  测试类.前端类      12K*14.6 + 800饭补(400+20*20)  (2014)                  产品本硕           

微软2014编程之美初赛第一场——题目2 : 树

[来源] 题目2 : 树 [分析] 依据输入情况建立起树的模型.树的表示是一个表明父亲节点的数组.核心算法有两个: 计算某一节点的深度.用循环实现,一直向上找父亲节点,直到找到根节点.计算循环的次数即为深度. 计算某一节点的全部子节点.用递归实现. 本题在实现上节点的命名从0至N-1,与题目描写叙述不同. [代码] #include <iostream> #include <vector> using namespace std; vector<int> childre

腾讯2014实习生笔试题--德梅齐里亚克砝码问题

问题 珠宝商甲需要去鉴定一批41克以下的宝石(可能是41克以下不包括41克的任意重量),他只能携带一个天平和四个砝码去称重,请问他会携带那些重量的砝码?-----2014腾讯暑期实习生附加题第一题 解答: 首先给出问题的答案,聪明的人看到答案的形式就能猜到其中的规律:1,1*2+1=3,(1+3)*2+1=9,(1+3+9)*2+1=27. 德梅齐里亚克砝码问题问题描述: 一位商人有一个40磅的砝码,由于跌落在地而碎成4块.后来,称得每块碎片的重量都是整磅数,而且可以用这4块来称从1至40磅之间

微软2014年12月安全补丁 提醒及时修复

2014年最后一批微软补丁来了,北京时间12月10日凌晨,微软准时发布12月安全公告https://technet.microsoft.com/library/security/ms14-dec  目前服务器安全狗也已第一时间推送安全更新,为避免漏洞被利用遭到攻击,请及时修复服务器安全狗提示给您的系统高危漏洞! 本次安全公告带来7枚补丁,共涉及3个"严重"级别和4个"重要"级别,修复 Windows 系统.IE 浏览器以及 Office 组件中的24处漏洞.这7枚补

2014年美团校招之——服务器调度

思路: t[i] 表示第i台服务器完成一项任务所需要的时间,m台服务器,n个任务,实际上就是尽量是某台机器完成任务所花费的时间最短. public int estimateProcessTime(int[] t , int m , int n){ //每台服务器的任务数数组 int[] numOfTask = new int[m]; int min = -1; //开始尝试分配任务 for(int i = 0; i < n ; i++){ min = (numOfTask[0] + 1) * t

微软2014 算法笔试题目1及答案

题目1 : Beautiful String 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 We say a string is beautiful if it has the equal amount of 3 or more continuous letters (in increasing order.) Here are some example of valid beautiful strings: "abc", "cde"