华为2015合肥机试

//华为机试第一题:取十个数字(可重复)中不重复的最大三位数,构成最大三位数
void main()
{
	int num[10];
	for(int i = 0; i < 10;++i)
	{
		num[i] = 0;
	}
	int index = 0;
	for(int i = 0; i < 10; ++i)
	{
		std::cin>>index;
		num[index]++;
	}
	int max = 0;
	int count = 0;
	for(int i = 9; count != 3 && i >= 0; --i)
	{
		if(num[i] != 0)
		{
			max = max * 10 + i;
			count++;
		}
	}
	std::cout<<max<<std::endl;
	system("pause");
}


//第二题:确定最小需要拆开盒子个数,包含多组输入
//输入: <<<A>>><>
//       <A>
//输出: 3
//       1
void main()
{
	std::string str;
	int arr[50];//对个数进行统计
	int com = 0;
	while(std::cin>>str)
	{
		int len = str.length();
		int count = 0;
		int travel = 0;
		while(str[travel] != 'A' && travel != len)
		{
			if(str[travel] == '(')
				count++;
			else if(str[travel] == ')')
				count--;
			travel++;
		}
		arr[com++] = count;
	}
	for(int i = 0; i < com; ++i)
	{
		std::cout<<arr[i]<<std::endl;
	}
	system("pause");
}


//第三题,和尚挑水,七个和尚,一周七天。每个人的安排挑水时间不同,输出所有的跳水可能排列组合
//输入:0 表示该和尚当天不可挑水, 1 表示该和尚当天可挑水
//输入:1 0 1 0 1 0 1
//      0 1 0 1 0 1 0
//      ....
//输出 4
//     1 2 3 5 4 6 7
//     ....
int stack[7];
std::vector<int*> stack_record;
std::set<int> mon;
int count = 0;
void findNext(int record[7][7],int depth)
{
	if(depth == 7)
	{
		count++;
		int* numPtr = new int[7];
		for(int i = 0; i < 7; ++i)
		{
			numPtr[i] = stack[i] + 1;
		}
		stack_record.push_back(numPtr);
	}
	else
	{
		for(int i = 0; i < 7;i++)
		{
			if(record[i][depth] == 1 && mon.count(i) == 0)
			{
				stack[depth] = i;
				mon.insert(i);
				findNext(record,depth+1);
				mon.erase(i);
			}
		}
	}
}
void main()
{
	int record[7][7];
	for(int i = 0; i < 7; ++i)
	{
		for(int j = 0; j < 7; ++j)
		{
			std::cin>>record[i][j];
		}
	}
	findNext(record,0);
	std::cout<<stack_record.size()<<std::endl;
	for(int i = 0; i < stack_record.size(); ++i)
	{
		int *tmp = stack_record[i];
		for(int j = 0; j < 7; ++j)
		{
			std::cout<<tmp[j]<<" ";
		}
		std::cout<<std::endl;
	}
	system("pause");
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值