2045 - 2020GEC1506 - Encode Scoreboard

Time

2020/05/26 23:30:00 2020/06/02 12:00:00

Clarification

# Problem Asker Description Reply Replier Reply Time For all team

# Problem Pass Rate (passed user / total user)
12269 GEC1506 - Basic - Encoding

12269 - GEC1506 - Basic - Encoding   

Description

 

Given a few lines of text, you are required to parse it and perform the following operations:

  1. Count the frequency of each character in the text (excluding spaces).
  2. If multiple characters have the same frequency, order them according to their first occurrence in the text.
  3. Encode the characters according to their frequency, replacing each character with a corresponding lowercase letter from the alphabet (a-z) in alphabetical order.

Input

 

The input will consist multiple lines of text.

  • 1 <= Number of lines <= 10^2
  • 1 <= len(text) <= 10^4
  • The text will only contain lowercase alphabetical characters and spaces.

Output

 

  • The output should be the encoded version of the input text, with the most frequent character replaced by 'a', the second most frequent character replaced by 'b', and so on.
  • Spaces in the input text should be preserved in the output.(You don't need to encode the space character ' '.)
  • You should start to count the frequency after you receive all the input

 

Example input:


hello john
how are you



Example output:

bcdda eabf
bag hic jak

 

After counting and sorting the characters based on their frequency and order of occurrence, we have:

  • 'o' occurs 4 times
  • 'h' occurs 3 times
  • 'e', 'l' occurs 2 times
  • 'j', 'n', 'w', 'a', 'r', 'y', and 'u' occur 1 time each

 

Encoding the characters:

  • 'o' -> 'a'
  • 'h' -> 'b'
  • 'e' -> 'c'
  • 'l' -> 'd'
  • 'j' -> 'e'
  • 'n' -> 'f'
  • 'w' -> 'g'
  • 'a' -> 'h'
  • 'r' -> 'i'
  • 'y' -> 'j'
  • 'u' -> 'k'

Sample Input  Download

Sample Output  Download

Tags




Discuss