Programming contests

20 Programming Exercise for Beginners

January 1, 2019, 12:00 AM – December 31, 2019, 12:00 AM

Character Counting

Create a program that computes the number of occurrences of the different characters in each input line and prints to the output the character with the most occurrences. Only a single character needs to be printed. If more than one character satisfies the condition, then the one which occurred earlier must be printed.

Input Specification

The input consists of nonempty lines containing printable ASCII characters.

Sample Input

  1. abcdefg
  2. aabbbccc
download as text file

Output for Sample Input

  1. a
  2. b
download as text file

Hints and Guide

Because the number of printable ASCII characters are limited, we can count them by using an integer array where each value of the array stores the number of occurrences of a particular character. ASCII characters are represented as numbers (ASCII codes) from 32 to 127. These numbers can be used as indexes of the array. Note that the array indexing starts with 0.

One possible solution is available in: main.c.

Acknowledgement This work was supported by the construction EFOP-3.4.3-16-2016-00021. The project was supported by the European Union, co-financed by the European Social Fund.
University of Debrecen; Faculty of Informatics; v. 09/30/2024