Algorithm


Problem Name: 2 AD-HOC - beecrowd | 2252

Problem Link: https://www.beecrowd.com.br/judge/en/problems/view/2252

Discovering Password

 

By George Albuquerque Pinto, UEVA BR Brazil

Timelimit: 1

Sherlock is a very smart boy, who was born in London in England. Since two years he always liked to solve challenges. With three years was school champion Sudoku. His uncle Paul Harrison always liked to challenge the boy bringing logic problems. This time Paul issued a challenge, but it is not only a challenge, he wants to find out his boss room password to be able to pick up some important documents of the company. Your task is to build a program that will help your uncle with this problem, given the information on the amount of oil on each key.

For example, 0 = 0.80, 1 = 12:12, 2 = 0.01, 3 = 00:22, 4 = 00:35, 5 = 12:25, 6 = 0.77, 7 = 12:50, 8 = 0.63, 9 = 0:45 and n = 5, the password will be 06,879 .

 

Input

 

The input consists of several test cases, and is completed with file end. The first line in each case consists of an integer value N (0 < N < 11) which corresponds to the number of digits of the password. In the following section reads 10 values Vi, where (0 <= Vi <1), the i-th value corresponds to the level of oiliness i-th lock key. The higher the level oleosedade more times it has been used key. The password does not contain repeated digits formed and is formed by N digits plus ultilizados.

 

Output

 

For each test case print a line with the message "Case k" where k indicates the test case number followed by access to the boss room password. Show results as the sample output. If two keys have the same level of greasiness, the key with the smaller value must precede the other. Print the password so that it starts showing the highest oiliness key to the smallest.

 

 

 

Input Sample Output Sample

5
0.02 0.23 0.07 0.18 0.17 0.72 0.48 0.36 0.67 0.35
4
0.76 0.52 0.74 0.19 0.15 0.99 0.13 0.59 0.48 0.45
4
0.83 0.86 0.37 0.16 0.41 0.38 0.36 0.67 0.32 0.20

Caso 1: 58679
Caso 2: 5027
Caso 3: 1074

 

Code Examples

#1 Code Example with C Programming

Code - C Programming


#include <stdio.h>
#include <stdbool.h>
#include <string.h>

typedef struct digito{

	float digito;
	unsigned short posicao;

} digito;

void ordena(digito *, unsigned short tam);

int main (void)
{

	unsigned short qtsDigitos;
	unsigned short qtsCasos = 0;
	unsigned short i;
	digito senha[10];

	while (scanf("%hu", &qtsDigitos) != EOF)
	{


		for (i = 0; i  <  10; i++)
		{

			scanf("%f", &senha[i].digito);
			senha[i].posicao = i;

		}

		ordena(senha, 10);

		printf("Caso %hu: ", ++qtsCasos);
		for (i = 0; i  <  qtsDigitos; i++)
			printf("%hu", senha[i].posicao);

		printf("\n");

		memset(senha, 0, sizeof(senha));

	}

}

void ordena(digito *senha, unsigned short tam)
{

	short i = 1, j;
	digito pivo;

	while (i  <  tam)
	{

		j = i - 1;
		pivo = senha[i];

		while(j >= 0 && senha[j].digito  <  pivo.digito)
		{

			senha[j + 1] = senha[j];
			j--;

		}

		senha[j + 1] = pivo;
		i++;

	}

}
Copy The Code & Try With Live Editor

Input

x
+
cmd
5
0.02 0.23 0.07 0.18 0.17 0.72 0.48 0.36 0.67 0.35
4
0.76 0.52 0.74 0.19 0.15 0.99 0.13 0.59 0.48 0.45
4
0.83 0.86 0.37 0.16 0.41 0.38 0.36 0.67 0.32 0.20

Output

x
+
cmd
Caso 1: 58679
Caso 2: 5027
Caso 3: 1074
Advertisements

Demonstration


Previous
#2251 Beecrowd Online Judge Solution 2251 Towers of Hanoi Solution in C, C++, Java, Js and Python
Next
#2285 Beecrowd Online Judge Solution 2285 Palíndrome Solution in C, C++, Java, Js and Python