FLAMES is a popular game named after the acronym: Friends, Lovers, Affectionate, Marriage, Enemies, Sibling. This game does not accurately predict whether or not an individual is right for you, but it can be fun to play this with your friends.
There are two steps in this game:
- Get the count:
- Take the two names.
- Remove the common characters with their respective common occurrences.
- Get the count of the characters that are left .
Get the result :
- Take FLAMES letters as [“F”, “L”, “A”, “M”, “E”, “S”]
- Start removing letter using the count we got.
- The letter which last the process is the result.
Input: Player1 = AJAY, Player2 = PRIYA Output: Friends
Explanation: In above given two names A and Y are common letters which are occurring one time(common count) in both names so we are removing these letters from both names. Now count the total letters that are left here it is 5. Now start removing letters one by one from FLAMES using the count we got and the letter which lasts the process is the result.
Counting is done in an anti-clockwise circular fashion.
counting starts from F, E is at 5th count so we remove E and start counting again but this time start from S.
M is at 5th count so we remove M and counting starts from S.
S is at 5th count so we remove S and counting start from F.
L is at 5th count so we remove L and counting starts from A.
A is at 5th count so we remove A. now we have only one letter is remaining so this is the final answer.
So, the relationship is F i.e. Friends .
Approach: Three counters are required, two for the names initialized at zero, and one for flames initialized at 5. Three strings are used, two for names and one, where FLAMES is already stored. Here the program first calculated the number of letters in the first name and then calculated the number of letters in second name Then after storing them using strlen into integer variables, one for loop is run for each name to count the common letters. Then by using nested if-else the letters are cancelled from each name, which is represented by a string. The for loop is again repeated to continue this process. Accordingly, the counter rotates and each letter in FLAMES is pointed at. As letters get canceled the loop is run again. Then for each letter, an If else statement is used, Print the result corresponding to the last letter.
Below is the implementation :
AJAY is FRIEND to PRIYA
GeeksforGeeks has prepared a complete interview preparation course with premium videos, theory, practice problems, TA support and many more features. Please refer Placement 100 for details
- Program to implement ASCII lookup table
- Implement a Dictionary using Trie
- How to implement is functionality without using is keyword in C#
- Find the winner of the game
- Find the winner of a game where scores are given as a binary string
- Program to get the subdomain of a URL using PHP
- Program to find the sum of the series (1/a + 2/a^2 + 3/a^3 + ... + n/a^n)
- Program to print last N lines | Set-2
- Hello World Program in Perl
- Program to check if two strings are same or not
- Program to Encrypt a String using ! and @
- Difference between Program and Process
- Program to check for ISBN
- Program to find the initials of a name.
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.