SMSDICT - Editorial

PROBLEM LINK:
Practice

Author: Rupanjan Hari

Tester: Rupanjan Hari

DIFFICULTY
: Easy

PREREQUISITES
: Math

QUICK EXPLANATION

For each word in the input, compute the number key sequence that creates it by inverting the mapping 2→{a,b,c}, 3→{d,e,f} etc. Store the number corresponding to the word in an array. After reading all the input, sort the numbers in the array.

EXPLANATION

The program is divided into different functions to make the logic more understandable.

Arrays:

char A[][9] - This character array map stores the digit corresponding to each letter. char word[n][20] - This is the primary array that stores the input words. int number[n] - This array stores the digits for the letters of each word as a number.

Functions:

int inverMap(char ch) - Returns the the digit corresponding a letter in the input word. void sort(int a[],int n) - Sorts a no. wrt it's digits. int maxTyped(int a[],int n) - Returns the maximum typed digit among all.

For each input word, what you need to do is that obtain the key map from the inverMap(char) method. Insert that into the correct position of the number[] array. Sort the digits of the obtained number using sort(int[],int) method. Get the maximum typed digit among all using maxTyped(int[],int) method & print it.

SOLUTION:
click here to see the solution