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;}
- codechef Birthday Candles 题解
- codechef Turbo Sort 题解
- codechef Ambiguous Permutations 题解
- codechef Prime Palindromes 题解
- Codechef Nuclear Reactors 题解
- codechef Cleaning Up 题解
- codechef Permutation Cycles 题解
- codechef Cutting Recipes题解
- codechef Carvans 题解
- Codechef Racing Horses题解
- codechef Hotel Bytelandia题解
- codechef Top Batsmen题解
- codechef Attic Crossing 题解
- codechef Recipe Reconstruction 题解
- codechef : Marbles 题解
- CodeChef AUG17 简要题解
- CodeChef SEPT17 简要题解
- CodeChef November Challenge 2013 题解
- C#.NET中怎样打开一个新Form,同时关闭当前Form?
- html
- 初入职场新人规划
- openstack_swift源码分析——Swift单机部署
- P2P的原理和常见的实现方式(为libjingle开路)
- codechef Birthday Candles 题解
- cpp's most vexing parse
- 小小的太阳
- java中的string equals 与 == 的比较
- 程序猿进化必读:让App的运行速度与响应速度趋于一流(iOS)
- io读取文件内容乱码处理
- c# 如何16进制颜色值转换成color值
- FMDatabase 的使用方法
- C# WinForm弹出窗口的两种方式