Algorithm


Problem Name: beecrowd | 2311

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

Diving

 

By Leonardo Fernandes, IFSC BR Brazil

Timelimit: 1

In a given diving competition, each dive has a degree of difficulty and is evaluated by seven judges. After each jump, the judges, who don't communicate with each other, show their scores. A dive is evaluated between zero and ten by each judge. After the scores are presented, the highest and the lowest scores are discarded. The remaining scores are added and the sum is multiplied by the degree of difficulty of the dive, which is a number between 1.2 and 3.8 defined before the dive. So, for example, assuming a diver's jump has difficulty 2.0 and his scores are 6,0, 5,0, 5,0, 5,0, 5,0, 5,0 and 4,0. Discarding the highest and lowest scores, we get to a result of 25.0. This result is then multiplied by the degree of difficulty 2.0 for a final score of 50.0. You program must display the results of a competition following these rules.

 

Input

 

The first row of input has the number of diversN (0 ≤ N ≤ 100). Next, the name of each competitor is followed by the degree of difficulty D (1.2 ≤ D ≤ 3.8) of the dive and, in the next line, the seven scores S1 to S7 (0 ≤ S1 to S7 ≤ 10)given by the judges.

 

Output

 

The output must show the results of the competition, with the name of each diver followed by the final score, in the order in which the data was input.

 

 

 

Input Sample Output Sample

3
Gabriela
2.0
6.0 5.0 5.0 5.0 5.0 5.0 4.0
Marina
1.5
8.5 7.0 8.0 8.0 8.4 7.5 7.7
Mafalda
3.0
6.0 7.0 6.5 6.8 7.9 6.2 6.6

Gabriela 50.00
Marina 59.40
Mafalda 99.30

 

Code Examples

#1 Code Example with C Programming

Code - C Programming


#include <stdio.h>

struct info
{
    char str[100];
    float b;
    float a[7];
};

int main(void)

{
    int i, j, n;
    float min, max, ans, sum;

    scanf("%i", &n);

    struct info dive[n];

    for (i = 0; i  <  n; ++i)
    {
        scanf("%s %f", dive[i].str, &dive[i].b);

        sum=0.0;

        for (j = 0; j  <  7; ++j)
        {
            scanf("%f", &dive[i].a[j]);
            sum+=dive[i].a[j];
        }

        min=dive[i].a[0];
        max=dive[i].a[0];

        for (j = 0; j  <  7; ++j)
        {
            if (dive[i].a[j] > max)
                max = dive[i].a[j];

            if (dive[i].a[j]  <  min)
                min = dive[i].a[j];
        }

        sum-=(max+min);
        ans=sum*dive[i].b;

        printf("%s %.2f\n", dive[i].str, ans);
    }

    return 0;
}
Copy The Code & Try With Live Editor

Input

x
+
cmd
3 Gabriela 2.0 6.0 5.0 5.0 5.0 5.0 5.0 4.0 Marina 1.5 8.5 7.0 8.0 8.0 8.4 7.5 7.7 Mafalda 3.0 6.0 7.0 6.5 6.8 7.9 6.2 6.6

Output

x
+
cmd
Gabriela 50.00 Marina 59.40 Mafalda 99.30

#2 Code Example with C++ Programming

Code - C++ Programming


#include <iostream>
#include <ostream>
#include <string>

int main(){
    int n, i;
    double difficult, score[7], less, max,total;
    std::string diver;
    std::cin >> n;
    while (n--) {
        std::cin >> diver >> difficult;
        for (i = 0;i  <  7;i++) {
            std::cin >> score[i];
            total += score[i];
        }
        max = score[0];
        less = score[0];
        for (i = 0;i  <  7;i++) {
            if (max < score[i]) {
                max = score[i];
            }
            if (less > score[i]) {
                less = score[i];
            }

        }
        std::cout.precision(2);
        std::cout.setf(std::ios::fixed);
        std::cout << diver << " " << (total-less-max)*difficult << std::endl;
        total = 0;
    }

    return 0;
}
Copy The Code & Try With Live Editor

Input

x
+
cmd
3 Gabriela 2.0 6.0 5.0 5.0 5.0 5.0 5.0 4.0 Marina 1.5 8.5 7.0 8.0 8.0 8.4 7.5 7.7 Mafalda 3.0 6.0 7.0 6.5 6.8 7.9 6.2 6.6

Output

x
+
cmd
Gabriela 50.00 Marina 59.40 Mafalda 99.30

#3 Code Example with Javascript Programming

Code - Javascript Programming


var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var lines = input.split('\n');
var prompt = function(texto) { return lines.shift();};
const cases = parseInt(prompt());

for (let i = 0; i  <  cases; i++) {
  var diver = prompt();
  var difficulty = parseFloat(prompt());
  var scores = prompt().split(" ").map(Number);
  var result = 0;

  let lowest = scores[0];
  let highest = scores[0];
  for (let i = 1; i  <  7; i++) {
    lowest = (lowest + scores[i] - Math.abs(lowest - scores[i])) / 2;
    lowest = parseFloat(lowest.toFixed(1));
    highest = (highest + scores[i] + Math.abs(highest - scores[i])) / 2;
    highest = parseFloat(highest.toFixed(1));
  }

  scores.splice(scores.indexOf(lowest), 1);
  scores.splice(scores.indexOf(highest), 1);

  for (let value of scores) {
    result = result + value;
  }
  result = result * difficulty;

  console.log(diver + " " + result.toFixed(2));
}

Copy The Code & Try With Live Editor

Input

x
+
cmd
3 Gabriela 2.0 6.0 5.0 5.0 5.0 5.0 5.0 4.0 Marina 1.5 8.5 7.0 8.0 8.0 8.4 7.5 7.7 Mafalda 3.0 6.0 7.0 6.5 6.8 7.9 6.2 6.6

Output

x
+
cmd
Gabriela 50.00 Marina 59.40 Mafalda 99.30

#4 Code Example with Python Programming

Code - Python Programming


n = int(input())
while n:
    n -= 1
    nome = input()
    gd = float(input())
    nota = [float(x) for x in input().split()]
    nota = sum(sorted(nota)[1:6]) * gd
    print('%s %.2f' % (nome, nota))
Copy The Code & Try With Live Editor

Input

x
+
cmd
3 Gabriela 2.0 6.0 5.0 5.0 5.0 5.0 5.0 4.0 Marina 1.5 8.5 7.0 8.0 8.0 8.4 7.5 7.7 Mafalda 3.0 6.0 7.0 6.5 6.8 7.9 6.2 6.6

Output

x
+
cmd
Gabriela 50.00 Marina 59.40 Mafalda 99.30
Advertisements

Demonstration


Previous
#2310 Beecrowd Online Judge Solution 2310 Volleyball Solution in C, C++, Java, Js and Python
Next
#2312 Beecrowd Online Judge Solution 2312 Medal Table Solution in C, C++, Java, Js and Python