去哪儿网2014年校园招聘笔试题(成都)

1. implement a function of String randomAlphabetic(int count)

Creats a random string whose length is the number of characters specified;

Characters will be chosen from the set of alphabetic characters.

#include <iostream>
#include <string>
#include <time.h>
using namespace std;

string randomAlphabetic(int count)
{
	string str;
	srand((unsigned int)time(NULL));
	int random;
	char randomChar;

	while (count--)
	{
		random = rand() % 26;
		if (rand() % 2 == 0)
		{
			randomChar = 'a' + random;
		}
		else
		{
			randomChar = 'A' + random;
		}

		str += randomChar;
	}

	return str;
}

int main()
{
	int count;
	while (cin>>count)
	{
		string str = randomAlphabetic(count);
		cout<<str<<endl;
	}

	return 0;
}

2. 已知字母序列【d, g, e, c, f, b, o, a】,请实现一个函数针对输入的一组字符串 input[] = {"bed", "dog", "dear", "eye"},按照字母顺序排序并打印。

本例的输出顺序为:dear, dog, eye, bed。

 

3. 有一万个北京单身男女向你提交了基本资料,包括:姓名、性别、年龄、星座,写一段程序尝试找出他们最匹配的一对。

你可能感兴趣的:(去哪儿网2014年校园招聘笔试题(成都))