## Algorithm

Problem Name: beecrowd | 2949

# The Fellowship of the Ring

By Samuel Eduardo da Silva, IFSULDEMINAS/UFF Brazil

Timelimit: 1

Frodo was a little hobbit (small, hairy-footed people) who lived quietly in the Shire, taking his various breakfasts filled with many succulent foods that a good hobbit diet provides.
One day his Uncle Bilbo hands him his famous golden ring, and Gandalf, a very "cool" mage, tells Frodo that this ring was not normal and should be thrown on the Mountain of Doom, so that a great evil would be avoided. For this journey, an entourage was formed, composed of dwarves, elves, humans, hobbits and magicians.
Frodo wants to know the amount of each race that will go with him for the journey. Given a list of people who enlisted, report back to Frodo from the entourage.

## Input

The first line of the entry is composed of an integer N(0 < N <= 10), indicating the number of people who enlisted. Each of the next N Next lines are composed of a string (without spaces and of alphanumeric characters only) and a capital character, indicating, respectively, the name and the type of the race of the respective being. This character may be:
● A - For dwarves;
● E - For elves;
● H - For humans;
● M - For magicians;
● X - For hobbits (X, because every hobbit is a mystery to the world).

## Output

A report should be presented with Frodo's entourage, indicating in each line how many beings of each species will be on the journey, following the order: hobbits, humans, elves, dwarves and magicians (in Portuguese).

 Input Sample Output Sample 9 Frodo X Gandalf M Pippin X Sam X Aragorn H Legolas E Gimli A Boromir H Merry X 4 Hobbit(s) 2 Humano(s) 1 Elfo(s) 1 Anao(oes) 1 Mago(s)

## 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

int main(int argc, char **argv)
{

int n;
char c;
char nome[100];
int ans[5] = { 0 };

scanf("%d", &n);

while (n--)
{

scanf("%s %c", nome, &c);

if (c == 'X')
ans[0]++;
else if (c == 'H')
ans[1]++;
else if (c == 'E')
ans[2]++;
else if (c == 'A')
ans[3]++;
else
ans[4]++;

}

printf("%d Hobbit(s)\n", ans[0]);
printf("%d Humano(s)\n", ans[1]);
printf("%d Elfo(s)\n", ans[2]);
printf("%d Anao(s)\n", ans[3]);
printf("%d Mago(s)\n", ans[4]);

return 0;

}
``````
Copy The Code &

Input

cmd
9 Frodo X Gandalf M Pippin X Sam X Aragorn H Legolas E Gimli A Boromir H Merry X

Output

cmd
4 Hobbit(s) 2 Humano(s) 1 Elfo(s) 1 Anao(oes) 1 Mago(s)

### #2 Code Example with Javascript Programming

```Code - Javascript Programming```

``````
const { readFileSync } = require("node:fs")
const [[numLines], ...input] = readFileSync("/dev/stdin", "utf8")
.split("\n", 1 + 10)
.map((line) => line.split(" ", 2))

function main() {
const RingSocietySpeciesReport = {
Hobbit: 0,
Human: 0,
Elf: 0,
Dwarf: 0,
Mage: 0
}

for (let index = 0; index  <  Number.parseInt(numLines, 10); index++) {
const [name, speciesClassCode] = input[index]
switch (speciesClassCode) {
case "A": RingSocietySpeciesReport.Dwarf++; break
case "E": RingSocietySpeciesReport.Elf++; break
case "H": RingSocietySpeciesReport.Human++; break
case "M": RingSocietySpeciesReport.Mage++; break
case "X": RingSocietySpeciesReport.Hobbit++; break
}
}

console.log(`\${RingSocietySpeciesReport.Hobbit} Hobbit(s)`)
console.log(`\${RingSocietySpeciesReport.Human} Humano(s)`)
console.log(`\${RingSocietySpeciesReport.Elf} Elfo(s)`)
console.log(`\${RingSocietySpeciesReport.Dwarf} Anao(oes)`)
console.log(`\${RingSocietySpeciesReport.Mage} Mago(s)`)
}

main()

``````
Copy The Code &

Input

cmd
9 Frodo X Gandalf M Pippin X Sam X Aragorn H Legolas E Gimli A Boromir H Merry X

Output

cmd
4 Hobbit(s) 2 Humano(s) 1 Elfo(s) 1 Anao(oes) 1 Mago(s)

### #3 Code Example with Python Programming

```Code - Python Programming```

``````
from collections import defaultdict

N = int(input())

i = 1
# comitiva = {
#     'anoes': 0,
#     'elfos': 0,
#     'humanos': 0,
#     'magos': 0,
#     'hobbits': 0
# }

comitiva = {}

comitiva = defaultdict(lambda : 0, comitiva) # Ele fornece um valor padrão para a chave que não existe.

while i <= N:
nome_raca, tipo = map(str, input().split())
if tipo == 'A':
comitiva['anoes'] += 1
if tipo == 'E':
comitiva['elfos'] += 1
if tipo == 'H':
comitiva['humanos'] += 1
if tipo == 'M':
comitiva['magos'] += 1
if tipo == 'X':
comitiva['hobbits'] += 1

i += 1

print("{} Hobbit(s)\n{} Humano(s)\n{} Elfo(s)\n{} Anao(s)\n{} Mago(s)".format(comitiva['hobbits'],comitiva['humanos'],comitiva['elfos'], comitiva['anoes'], comitiva['magos']))
``````
Copy The Code &

Input

cmd
9 Frodo X Gandalf M Pippin X Sam X Aragorn H Legolas E Gimli A Boromir H Merry X

Output

cmd
4 Hobbit(s) 2 Humano(s) 1 Elfo(s) 1 Anao(oes) 1 Mago(s)