Algorithm
Problem Name: 2 AD-HOC - beecrowd | 2250
Problem Link: https://www.beecrowd.com.br/judge/en/problems/view/2250
Tetris
By OBI - Olimpíada Brasileira de Informática 2003 Brazil
Timelimit: 1
Your school class decided to organize a championship tetris. After discussion of the rules, it was decided that each student would play a total of 12 matches. Of the 12 points obtained by a student, the highest and lowest are discarded, and the others are added, resulting in the final score of the student.
As you have programming skills, it ended up being assigned the class to write a program to print the final classification of the championship, from the scores of each player.
Input
The input consists of several test sets. The first line contains a set of tests an integer J (0 ≤ J ≤ 1000), indicating the number of players who participated in the championship. Next, for each player there are two lines at the entrance: the first has the name of the player (formed only by letters, being only the initial capital, and with a maximum of 15 letters), and the second has 12 scores the player obtained, separated by a space. The scores are integers between 0 and 1000. The end of entry is indicated by a test set with J = 0.
Output
For each test set, your program must write one line containing the test set identifier in the "Teste n" format, where n is sequentially numbered from 1. Next, your program should write the final classification in championship, using one line for each attendee. Each line must contain three pieces of information, separated by a blank space: the classification of the player, your final score and your name. The rating of a player is equal to 1 plus the number of players who scored more than his. In case of a tie, the players must be sorted in alphabetical order. After all the classification should be left with a blank line. The format of the sample output below should be followed strictly.
Input Sample | Output Sample |
4 Zezinho 100 123 133 333 400 300 129 200 360 340 200 600 Luizinho 60 50 120 250 170 190 190 220 260 270 290 300 Carlinhos 10 10 20 10 10 10 10 20 20 20 20 20 Joaozinho 200 300 400 400 500 500 500 600 650 650 700 810 3 Pedrinho 100 100 200 200 300 300 400 400 500 500 600 600 Huguinho 50 100 200 200 300 300 500 500 400 400 600 700 Zezinho 100 100 100 100 100 100 100 100 100 100 100 100 0 |
Teste 1 1 5200 Joaozinho 2 2518 Zezinho 3 2020 Luizinho 4 150 Carlinhos Teste 2 1 3500 Huguinho 1 3500 Pedrinho 3 1000 Zezinho |
Code Examples
#1 Code Example with C Programming
Code -
C Programming
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define true 1
#define false 0
#define MAX 1100
#define INF 0x3f3f3f
#define A competidores[i].pontos
#define C competidores[i].nome
typedef struct pessoa{
char nome[30];
unsigned short pontos;
} pessoa;
pessoa competidores[MAX];
int compara(pessoa *, pessoa *);
int main (void)
{
int tmp;
int maior, menor, pos;
unsigned short i, j, teste = 0;
unsigned short qtsCompetidores;
while (scanf("%hu", &qtsCompetidores), qtsCompetidores)
{
memset(competidores, 0, sizeof(competidores));
for (i = 0; i < qtsCompetidores; ++i)
{
scanf("%s", competidores[i].nome);
maior = -INF; menor = INF;
for (j = 0; j < 12; ++j)
{
scanf("%d", &tmp);
if (tmp > maior)
maior = tmp;
if (tmp < menor)
menor = tmp;
competidores[i].pontos += tmp;
}
competidores[i].pontos -= (menor + maior);
}
qsort(competidores, qtsCompetidores, sizeof(pessoa), compara);
maior = INF;
printf("Teste %hu\n", ++teste);
for (i = 0, pos = 1; i < qtsCompetidores; ++i)
{
if (A != maior)
pos = i + 1;
printf("%hu %u %s\n", pos, A, C);
maior = A;
}
printf("\n");
}
}
int compara(pessoa *a, pessoa *b)
{
if (a->pontos == b->pontos)
{
if (strcmp(a->nome, b->nome) == 0)
return 0;
else if (strcmp(a->nome, b->nome) > 0)
return 1;
else
return -1;
}
else if (a->pontos > b->pontos)
return -1;
else
return 1;
}
Copy The Code &
Try With Live Editor
Input
Zezinho
100 123 133 333 400 300 129 200 360 340 200 600
Luizinho
60 50 120 250 170 190 190 220 260 270 290 300
Carlinhos
10 10 20 10 10 10 10 20 20 20 20 20
Joaozinho
200 300 400 400 500 500 500 600 650 650 700 810
3
Pedrinho
100 100 200 200 300 300 400 400 500 500 600 600
Huguinho
50 100 200 200 300 300 500 500 400 400 600 700
Zezinho
100 100 100 100 100 100 100 100 100 100 100 100
0
Output
1 5200 Joaozinho
2 2518 Zezinho
3 2020 Luizinho
4 150 Carlinhos
Teste 2
1 3500 Huguinho
1 3500 Pedrinho
3 1000 Zezinho
#2 Code Example with C++ Programming
Code -
C++ Programming
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
int n, teste = 1;
while (1) {
cin >> n;
if (n == 0) break;
vector < pair<int, string> > competidores;
vector<int> posicao;
for (int i = 1; i < = n; i++) {
string nome;
cin >> nome;
vector<int> temporario;
int resp = 0;
for (int j = 1; j < = 12; j++) {
int davez;
cin >> davez;
temporario.push_back(davez);
resp += davez;
}
sort(temporario.begin(), temporario.end());
competidores.push_back(
make_pair(temporario[0] + temporario[11] - resp, nome));
}
sort(competidores.begin(), competidores.end());
posicao.push_back(1);
for (int i = 1; i < n; i++) {
if (competidores[i].first == competidores[i - 1].first)
posicao.push_back(posicao[i - 1]);
else
posicao.push_back(i + 1);
}
cout << "Teste " << teste << endl;
teste++;
for (int i = 0; i < n; i++) {
cout << posicao[i] << " " << -competidores[i].first << " "
<< competidores[i].second << endl;
}
cout << endl;
}
return 0;
}
Copy The Code &
Try With Live Editor
Input
Zezinho
100 123 133 333 400 300 129 200 360 340 200 600
Luizinho
60 50 120 250 170 190 190 220 260 270 290 300
Carlinhos
10 10 20 10 10 10 10 20 20 20 20 20
Joaozinho
200 300 400 400 500 500 500 600 650 650 700 810
3
Pedrinho
100 100 200 200 300 300 400 400 500 500 600 600
Huguinho
50 100 200 200 300 300 500 500 400 400 600 700
Zezinho
100 100 100 100 100 100 100 100 100 100 100 100
0
Output
1 5200 Joaozinho
2 2518 Zezinho
3 2020 Luizinho
4 150 Carlinhos
Teste 2
1 3500 Huguinho
1 3500 Pedrinho
3 1000 Zezinho