Flames Program Question
Flames Program Question
Time: 90 minutes
Problem:
In school days, we used to play a game called FLAMES (F: Friend, L: Love, A: Attraction, M:
Marriage, E: Enemy, S: Sibling); which finds the relation between two names. Write a C program
that finds the relation between two names using the algorithm of FLAMES.
PS: Do not use string.h library.
[Disclaimer: Examples or names in this problem statement are unintentional. Any resemblance
in the real world is a mere coincidence.]
An example: Lets check the relation between Abhishek and Aishwarya.
Remove the common characters (case insensitive) from both the names. So, in the above problem
the characters A, i, s and h are common. (Remember there are three a in second name. But only
one a in first name and hence only once occurrence is common.) Now, the remaining number of
characters in both the names is 4 + 5 = 9; which is the number of iterations required for eliminating
a letter from FLAMES.
Now, you have to check the number 9 with FLAMES as explained below.
State 0: F L A M E S
Run/Count through FLAMES with number 9 like, F(1) L(2) A(3) M(4) E(5) S(6) F(7) L(8) A(9)
M E S. So, 9 end at A. Now delete A from FLAMES. Hence, remaining letters are FLMES.
State 1: F L M E S
Now, you have to start from M (just after where you had ended last time). So, M(1) E(2) S(3)
F(4) L(5) M(6) E(7) S(8) F(9) L E S. Delete F from FLMES. Hence, remaining letters are LMES.
State 2: L M E S
L(1) M(2) E(3) S(4) L(5) M(6) E(7) S(8) L(9) M E S: Delete L. Remaining MES.
State 3: M E S
M(1) E(2) S(3) M(4) E(5) S(6) M(7) E(8) S(9) M E S: Delete S. Remaining ME.
State 4: M E
M(1) E(2) M(3) E(4) M(5) E(6) M(7) E(8) M(9) E: Delete M. Remaining E.
State 5: E
The remaining character E gives the relation between the two persons: Abhishek and Aishwarya
are ENEMIES.
Page 2 of 4
Function Prototypes
Function to find the length of a string.
int StrLength ( char str []) ;
Ex. If str contains aaaakbaa and pos is 4. Then shiftLeft function modifies the str to aaaabaa.
Function to rearrange of a string.
void rearrange ( char str [] , int index ) ;
Ex. If str contains abcdef and index is 3. Then rearrange function rearranges the string str
to defabc.
Function to display a list of common characters and hence find the number of iterations required
(and returns it).
int findDiff ( char str1 [] , char str2 []) ;
Ex. If str1 is abcdab and str2 is abxymnd, findDiff function displays the following:
Common characters: a, b, d
Number of iterations required: 7
Input/Output Formats
Input
Names of two persons (no space or special characters).
Output
The program should display output as given in Sample I/O.
Final result need to be in the format: Name#1 and Name#2 are RELATION. (RELATION
can be obtained from FLAMES.)
Your program must display the intermediate results of FLAMES as well, i.e. the character deleted
in each step and the remaining characters.
Sample I/O:
Testcase 1:
Input
Enter Name#1: Abhishek
Enter Name#2: Aishwarya
Page 3 of 4
A, Remaining: mesfl
F, Remaining: lmes
l, Remaining: mes
s, Remaining: me
m, Remaining: e
Page 4 of 4