Count occurrences

0

0 votes
Data Structures, Basics of Hash Tables, Hash Tables, Easy, Hash table
Problem

You are given a particular string S, which contains only lowercase English alphabets. Your task is to calculate all the occurrences of the character and print the character in the order in which it appears in the string S followed by the number of occurrences.
Each character should appear only once in the output.

Example

Consider S = abab. You must determine the new string as given in the problem statement:

  • Count of a in the string is 2.
  • Count of b in the string is 2.

So final string would be a2b2.

Function description

Complete the CountOccurrences function provided in the editor. This function takes the following 1 parameters and returns desired string:

  • S: Represents the given string.

Input format

Note: This is the input format that you must use to provide custom input (available above the Compile and Test button).

  • The first line contains an integer, T, denoting the number of test cases.
  • Next T lines contain string S each.

Output format
For each test case, print the output in a new line.

Constraints
1T1000
1|S|1000 where S denotes the length of the string.

Code snippets (also called starter code/boilerplate code)

This question has code snippets for C, CPP, Java, and Python.

Sample Input
1
occurrences
Sample Output
o1c3u1r2e2n1s1
Time Limit: 1
Memory Limit: 256
Source Limit:
Explanation

In this case ‘o’ occurs only one time, ‘c’ occurs 3 times and so on.

Editor Image

?