codechef Birthday Candles 题解

来源:互联网 发布:竹子阿矛离婚知乎 编辑:程序博客网 时间:2024/05/16 15:06

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:

32 1 1 4 0 6 3 2 2 20 1 1 1 1 1 1 1 1 12 2 1 2 1 1 3 1 1 1 

Sample output:

41022

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

仔细想想我们是如何使用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;}




1 0
原创粉丝点击