#C13423. String Frequency Counter

    ID: 42960 Type: Default 1000ms 256MiB

String Frequency Counter

String Frequency Counter

Given an integer n representing the number of strings, followed by n lines each containing a string, count the frequency of each unique string. Output the frequency count of each string in lexicographical order.

Input Format:

  • The first line contains an integer n.
  • The next n lines each contain a single string.

Output Format:

  • For each unique string, output a line containing the string and its frequency separated by a space. The output should be sorted in lexicographical order by the string.

For example, if the input is:

6
apple
banana
apple
orange
banana
apple

Then the output should be:

apple 3
banana 2
orange 1

inputFormat

The input is provided via standard input (stdin) and consists of:

  • A single integer n on the first line.
  • n subsequent lines, each containing one string.

outputFormat

The output should be written to standard output (stdout) and contain multiple lines. Each line should consist of a unique string followed by its frequency, separated by a single space. The lines must be in lexicographical order by the string.

## sample
6
apple
banana
apple
orange
banana
apple
apple 3

banana 2 orange 1

</p>