EaglePB2's Competitive Programming Writeups
  • Home Page
  • Why Python?
  • Why 10^9 + 7?
  • General Formatting Title
  • 🇲🇾CodeNection
    • 2021
      • Closed Cateogry
        • Attend Talks
        • Distant Relatives
        • Concert
        • Mamak
        • Fair Contest
      • Open Preliminary Round
        • f(Aibohphobia)^-1
        • Did they cheat?
        • Semester Breaks
      • Open Final Round
        • Ways 1
        • Circular Campus
        • A joke
        • 🥰Last year when life was better
        • Thank You Pizza
    • 2023
      • Test Round
        • Codey and Alphabetical Scoring
        • Codey and Binary Guesser
      • Preliminary Round
        • Codey and CodeNection
        • Codey and Hide-and-Seek
        • Codey and Math
        • Codey and Textbooks
        • Codey and Money
        • Codey and Team Selection
        • Codey and Painted Tree
        • Codey and Number Grid
        • Codey and Crimes
      • Final Round
        • Codey and CodeNection 2
        • Codey and Connection
        • Codey and Schedule
        • Codey and School Supplies
        • Codey and Zombies
        • Codey and Sightseeing
        • Codey and Apples
        • Codey and Facto
        • Codey and Zoey
    • 2024
      • Test Round
        • Codey and Sunday
        • Codey and Takoyaki
      • Preliminary Round
        • Codey and CodeNection
        • Codey and Pebbles
        • Codey and Spam
        • Codey and Coins
        • Codey and Rectangles
        • Codey and Manuscript
        • Codey and Recipes
        • Codey and Toy Kingdom
        • Codey and Peaks
      • Final Round
        • Codey and Exit
        • Codey and Gardening
        • Codey and Symbol
        • Codey and Rectangles 2
        • Codey and Jutsu
        • Codey and Toy Kingdom 2
        • Codey and Speeches
  • ABaKoDa
    • 2023
      • Round 1
        • Problem Letters
        • Problem Statistics
        • Rankings Order
        • Rankings Search
      • Round 2
        • Abakoda Letters
        • Borrowed Words
        • Kensorship
        • Duel Languages
  • Meta Coding Competitions
    • 2011
      • Qualification Round
        • Double Squares
        • Peg Game
        • Studious Student
      • Round 1A
        • Diversity Number
        • Turn on the Lights
        • Wine Tasting
      • Round 1B
        • Chess 2
        • Diminishing Circle
        • Slot Machine Hacker
      • Round 1C
        • N-Factorful
        • Polynomial Factoring
        • Risky Slide
      • Round 2
        • Bonus Assignments
        • Scott's New Trick
        • Studious Student II
      • Final Round
        • Alien Game
        • Party Time
        • Safest Place
  • EaglePB2's Special
    • Hong Kong Identity card
    • Cycle Prefix Averages
    • Word Squares
Powered by GitBook
On this page
  • Question
  • Input Format
  • Constraints
  • Output Format
  • Sample Inputs:
  1. ABaKoDa
  2. 2023
  3. Round 1

Problem Statistics

https://codeforces.com/group/cRJbcAFEwS/contest/485694/problem/B

PreviousProblem LettersNextRankings Order

Last updated 2 months ago

Question

Abby and Cody want to make a new website called Abakoda, where beginner programmers can join friendly programming contests and improve their skills.

Now they are working on displaying the contest rankings. They need to show the number of contestants who have solved each problem on the bottom of the matching column of the rankings table.

Name
A
B
K
D

Aba

100

0

100

0

Abby

100

100

100

100

Koda

100

0

0

0

Cody

100

100

100

0

Solved By

4

2

3

1

Having this bottom row on the rankings can help contestants: if more people have solved a problem, it is probably easier.

Abby and Cody need your help. They already wrote code that gets which problems were solved by each contestant. Write a program that prints the number of contestants who have solved each problem.

Input Format

The input contains several lines.

The first line of input contains one integer n, the number of contestants.

This is followed by nnn lines of input. Each of these lines contains a string of capital letters, representing what problems were solved by a single contestant. The only letters that appear in these lines are A, B, K, or D. Each letter appears at most once in each string. The letters in a string are not necessarily arranged in alphabetical order. Each string is non-empty: every contestant solved at least one problem.

Constraints

Output Format

Your program must print a single line of output containing four integers separated by spaces: the number of contestants who solved problem A, followed by the number of contestants who solved problem B, followed by the number of contestants who solved problem K, followed by the number of contestants who solved problem D.

Sample Inputs:

Input

4
AK
ABKD
A
ABK

Output

4 2 3 1

Explanation:

In the first sample test case, there are four contestants.

  1. The first contestant solved problems A and K.

  2. The second contestant solved problems A, B, K, and D.

  3. The third contestant solved problem A.

  4. The fourth contestant solved problems A, B, and K.

Therefore, the correct output is 4 2 3 1.

Input

2
KAB
BDK

Output

1 2 2 1

Solution — Frequency Checker

This question can be solved by simply using frequency counter. It works as follows:

  • Create an array which has N size, which N is the unique type of items, while add 1 based on their "number", compared to their array index number.

  • For sync purposes, we need to -1 on the numbers as array starts from 0, meanwhile we count distinct values from 1.

  • After completing the frequency builder, the rest should be obvious.

Here's the solution:

counter = int(input())
arr_list = [0] * counter
all_freq = {}

for i in range(0, counter):
    arr_list[i] = input()
    for j in arr_list[i]:
        all_freq[j] += 1

print(str(all_freq["A"]) + " " + str(all_freq["B"]) + " " + str(all_freq["K"]) + " " + str(all_freq["D"]))

1≤n≤10001 \le n \le 10001≤n≤1000

A total of 444 contestants solved problem AAA. A total of 222 contestants solved problem BBB. A total of 333 contestants solved problem KKK. A total of 111 contestant solved problem DDD.

Page cover image