A minimum number of group PAT_B_1023

Subject description:

0-9 each given a number. You can arrange these numbers in any order, but must be fully utilized. The goal is to make the resulting number as small as possible (do not pay attention to the first 0). For example: Given two 0, 1 two, three 5, a 8, we get the minimum number is 10015558. 
The minimum number is now given a number, please write program output can be composed of. 
Input format: 
input non-negative integer gives 10 in a row, we have the sequence represents the number 0, the number of number 1, number 9 ....... Separated by a space between integer. The total number of 10 digits is no more than 50, and has at least one non-zero digit. 
Output format: 
smallest number in a row can be output thereof. 
Sample input: 
2200030010 
Output Sample: 
10015558

I AC Code:

// PAT_1023_Min_Number

# include <stdio.h> 

int main(void)
{
	int i, j, k=0;
	int N[10];
	int New[50];
	int len = 0;
	
	for (i=0; i<10; i++)
	{
		scanf("%d",&N[i]);
		len += N[i];
	}
	
	// 输入数据 
	for (i=0; i<10; i++)
	{
		for (j=0; j<N[i]; j++)
		{
			New[k++] = i;
		 } 
	}
	//  调整格式
	if (New[0] == 0) 
	{
		for (i=1; i<len; i++)
		{
			if (New[i] != 0)
			{
				New[0] = New[i];
				New[i] = 0; 
				break;
			}
		}
	}
	 
	// output array 
	for (I = 0; I <len; I ++) 
	{ 
		the printf ( "% D", New [I]); 
	 } 
	 
	return 0; 
}

RRR

Guess you like

Origin www.cnblogs.com/Robin5/p/11243699.html