Algorithm


Problem Name: beecrowd | 1789

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

The Race of Slugs

 

By Thalyson Nepomuceno, UECE BR Brazil

Timelimit: 1

The slugs racing is a sport that has grown in recent years, causing several people dedicate their lives trying to capture fast slugs, and trains them to make millions in races around the world. But the task of capturing fast slugs is not an easy task, since almost all the slugs are very slow. Each slug is classified at a level depending on their speed:


Level 1: If speed is less than 10 cm/h.
Level 2: If speed is greater than or equal to 10 cm/h and lower than 20 cm/h.
Level 3: If speed is greater than or equal to 20 cm/h.


Your task is to identify which level of speed faster slug of a group of slugs.

 

Input

 

The entry consists consists multiple test cases, and each consists of two lines: The first line contains an integer L (1 ≤ L ≤ 500) representing the number of slugs of the group, and the second line contains L integers Vi (1 ≤ Vi ≤ 50) representing the speeds of each slug.
The input ends with end of file (EOF).

 

Output

 

For each test case, output a single line with the level of speed faster slug of a group of slugs.

 

 

 

Input Sample Output Sample

10
10 10 10 10 15 18 20 15 11 10
10
1 5 2 9 5 5 8 4 4 3
10
19 9 1 4 5 8 6 11 9 7

3
1
2

 

Code Examples

#1 Code Example with C++ Programming

Code - C++ Programming


#include <iostream>

int get_level(int speed) {
    if (speed  <  10) {
        return 1;
    }
    if (speed < 20) {
        return 2;
    }
    return 3;
}

int main()
{
    int slugs{};

    while(std::cin >> slugs) 
    {
        int max_speed = 0;
        for (int i = 0; i  <  slugs; ++i)
        {
            int speed{};
            std::cin >> speed;
            if (speed > max_speed) 
            {
                max_speed = speed;
            }
        }
        std::cout << get_level(max_speed) << '\n';
    }
    return 0;
}
Copy The Code & Try With Live Editor

Input

x
+
cmd
10 10 10 10 10 15 18 20 15 11 10 10 1 5 2 9 5 5 8 4 4 3 10 19 9 1 4 5 8 6 11 9 7

Output

x
+
cmd
3 1 2

#2 Code Example with Javascript Programming

Code - Javascript Programming


var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var lines = input.split('\n');
let A = lines.shift();
let lesmas = lines.shift().split(" ");
let temp = lesmas[0];
let cont = 0;

while(lines.length != 0){
  for(let i = 0; i  <  lesmas.length, i < A; i++){ 
    if(parseInt(temp) > parseInt(lesmas[i])){
    }

    else{
      temp = lesmas[i];
      if(parseInt(temp) < 10){
        cont = 1;
      }
      else if(parseInt(temp> >= 10  && parseInt(temp)  <  20){
        cont = 2;
      }
      else if(parseInt(temp) >= 20){
        cont = 3;
      }
    }
  }
  console.log(cont);
  if(lines.length == 1){
    break;
  }
  A = lines.shift();
  lesmas = lines.shift().split(" ");
  cont = 0;
  temp = lesmas[0]; 
  
};
Copy The Code & Try With Live Editor

Input

x
+
cmd
10 10 10 10 10 15 18 20 15 11 10 10 1 5 2 9 5 5 8 4 4 3 10 19 9 1 4 5 8 6 11 9 7

Output

x
+
cmd
3 1 2
Advertisements

Demonstration


Previous
#1787 Beecrowd Online Judge Solution 1787 URI Solution in C, C++, Java, Js and Python
Next
#1793 Beecrowd Online Judge Solution 1793 Escalator Solution in C, C++, Java, Js and Python