Algorithm
Problem Name: 2 AD-HOC - beecrowd | 1953
Problem Link: https://www.beecrowd.com.br/judge/en/problems/view/1953
Robert and Rampant Room
By José Wagner de Andrade Junior, Universidade Federal de Itajubá - UNIFEI Brazil
Timelimit: 1
Roberto had to collect the enrollment number of students in your class production engineering and water engineering for the call. Soon, he had the great idea to talk to all students shouting the call numbers to write down his assistants. Obviously this does not work out, and soon the room collapsed. Everyone wanted to talk at once, and the competition to see who could go faster, there was a tumult of principle, with chairs being thrown on colleagues, hair pulling, and punch in the face.
Junior as a peaceful man, he is trying to fulfill all quickly. However, as are many requests, it is getting overloaded. He then remembered that you know how to program and decided to give an idea.
All classroom students should give the registration number and abbreviation of the course on a sheet, and the call will be computed later. They need to know how many students from each course attended. It has the data, but unfortunately does not have the required proficiency in programming for "CODE" it. You could help you to know, given a list of students, how many of EPR, how many of EHD and how many intruders?
Input
The first line of input an integer n (1 = n = 100 000) indicating the number of students in the class.
The following n lines contain the registration number and the symbol of the course.
The program playback should end with end of file.
Output
Your program should print three lines containing the number of students who are EPR, EHD and INTRUSOS in the format: "acronym: quantity." (See example output).
Input Sample | Output Sample |
4 27454 CCO 28415 EPR 66666 SATAN 1 EHD 1 123 EPR |
EPR: 1 EHD: 1 INTRUSOS: 2 EPR: 1 EHD: 0 INTRUSOS: 0 |
Code Examples
#1 Code Example with C Programming
Code -
C Programming
#include <stdio.h>
#include <string.h>
int main (void)
{
unsigned short engProd, engHidr, intrusos;
unsigned short casos, matricula;
while (scanf("%hu", &casos) != EOF)
{
char turma[100];
engProd = engHidr = intrusos = 0;
while (casos--)
{
scanf("%hu %s", &matricula, turma);
if (strcmp(turma, "EPR") == 0)
engProd++;
else if (strcmp(turma, "EHD") == 0)
engHidr++;
else
intrusos++;
}
printf("EPR: %hu\nEHD: %hu\nINTRUSOS: %hu\n", engProd, engHidr, intrusos);
}
}
Copy The Code &
Try With Live Editor
Input
27454 CCO
28415 EPR
66666 SATAN
1 EHD
1
123 EPR
Output
EHD: 1
INTRUSOS: 2
EPR: 1
EHD: 0
INTRUSOS: 0
#2 Code Example with C++ Programming
Code -
C++ Programming
#include <bits/stdc++.h>
using namespace std;
#define getcx getchar_unlocked
typedef long long ll;
int m;
int intruso;
int ehd;
int epr;
char s[5];
inline int inp( int &n )
{
n = 0;
ll ch = getcx();
if (ch == -1) return 0;
while (ch < '0' || ch > '9') ch = getcx();
while( ch >= '0' && ch <= '9' )
n = (n << 3) + (n << 1) + ch - '0', ch = getcx();
return 1;
}
inline void inp2()
{
int n = 0;
ll ch = getcx();
while (ch < 'A' || ch > 'Z') ch = getcx();
while( ch >= 'A' && ch <= 'Z' )
s[n++] = ch, ch = getcx();
s[n] = '\0';
}
int main()
{
int n;
//ios_base :: sync_with_stdio(0); cin.tie(0);
while (inp(n))
{
ehd = 0;
epr = 0;
intruso = 0;
for (int i = 0 ; i < n ; ++i)
{
inp(m);
inp2();
if (strcmp(s, "EHD") == 0) ++ehd;
else if (strcmp(s, "EPR") == 0) ++epr;
else ++intruso;
}
cout << "EPR: " << epr << "\nEHD: " << ehd << "\nINTRUSOS: " << intruso << '\n';
}
}
Copy The Code &
Try With Live Editor
Input
27454 CCO
28415 EPR
66666 SATAN
1 EHD
1
123 EPR
Output
EHD: 1
INTRUSOS: 2
EPR: 1
EHD: 0
INTRUSOS: 0