首页 > 其他 > 详细

codechef Birthday Candles 题解

时间:2014-05-04 18:46:44      阅读:530      评论:0      收藏:0      [点我收藏+]

Birthday Candles

The chef is preparing a birthday cake for one of his guests,
and his decided to write the age of the guest in candles on the cake.
There are 10 types of candles, one for each of the digits ‘0‘ through ‘9‘.
The chef has forgotten the age of the guest, however, so doesn‘t know whether he has enough candles of the right types.
For example, if the guest were 101 years old, the chef would need two ‘1‘ candles and one ‘0‘ candle.
Given the candles the chef has, your task is to determine the smallest positive integer that cannot be represented with those candles.

Input:

Input will begin with an integer T≤100, the number of test cases.
Each test case consists of a single line with exactly 10 integers, each between 0 and 8, inclusive.
The first integer of each test case represents the number of ‘0‘ candles the chef has,
the second integer represents the number of ‘1‘ candles the chef has, and so on.

Output:

For each test case, output on a single line the smallest positive integer that cannot be expressed with the given candles.

Sample input:

3
2 1 1 4 0 6 3 2 2 2
0 1 1 1 1 1 1 1 1 1
2 2 1 2 1 1 3 1 1 1
 

Sample output:

4
10
22

最小不能凑出来的数字组合。

仔细想想我们是如何使用0到9的一个数字组合出千千万万个数值的。

注意特殊情况: 零缺小的时候

#pragma once
#include <stdio.h>

int BirthdayCandles()
{
	static const int CANDLES = 10;
	int T;
	scanf("%d", &T);
	while (T--)
	{
		int A[CANDLES] = {0}, minCan = (1<<30), minId = 0;
		for (int i = 0; i < CANDLES; i++)
		{
			scanf("%d", &A[i]);
			if (minCan > A[i])
			{
				minCan = A[i];
				minId = i;
			}
		}
		if (0 == minId)
		{
			for (int i = CANDLES - 1; i > 0 ; i--)//注意有数等于0数的时候
			{
				if (minCan >= A[i])
				{
					minCan = A[i];
					minId = i;
				}
			}
			if (0 == minId) putchar(‘1‘);
		}
		while (minCan >= 0)
		{
			putchar(minId + ‘0‘);
			minCan--;
		}
		putchar(‘\n‘);
	}
	return 0;
}




codechef Birthday Candles 题解,布布扣,bubuko.com

codechef Birthday Candles 题解

原文:http://blog.csdn.net/kenden23/article/details/24962751

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!