# Program to implement FLAMES game

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.

Example :

```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.

FLAMES
counting starts from F, E is at 5th count so we remove E and start counting again but this time start from S.
FLAMS
M is at 5th count so we remove M and counting starts from S.
FLAS
S is at 5th count so we remove S and counting start from F.
FLA
L is at 5th count so we remove L and counting starts from A.
FA
A is at 5th count so we remove A. now we have only one letter is remaining so this is the final answer.
F
So, the relationship is F i.e. Friends .

## Recommended: Please try your approach on {IDE} first, before moving on to the solution.

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 :

## C++

 `// C++ program to implement FLAMES game ` `#include ` `using` `namespace` `std; ` ` `  `// Function to find out the flames result ` `void` `flame(``char``* a, ``char``* b) ` `{ ` `    ``int` `i, j, k, l = 1, n, m, sc = 0, tc, rc = 0, fc = 5; ` `    ``char` `q, w, c; ` `    ``char` `f[] = ``"flames"``; ` ` `  `    ``strcpy``(q, a); ` `    ``strcpy``(w, b); ` `    ``n = ``strlen``(a); ` `    ``m = ``strlen``(b); ` `    ``tc = n + m; ` ` `  `    ``for` `(i = 0; i < n; i++)  ` `    ``{ ` `        ``c = a[i]; ` `        ``for` `(j = 0; j < m; j++) ` `        ``{ ` `            ``if` `(c == b[j]) ` `            ``{ ` `                ``a[i] = -1; ` `                ``b[j] = -1; ` `                ``sc = sc + 2; ` `                ``break``; ` `            ``} ` `        ``} ` `    ``} ` ` `  `    ``rc = tc - sc; ` ` `  `    ``for` `(i = 0;; i++) ` `    ``{ ` `        ``if` `(l == (rc))  ` `        ``{ ` `            ``for` `(k = i; f[k] != ``'\0'``; k++)  ` `            ``{ ` `                ``f[k] = f[k + 1]; ` `            ``} ` `            ``f[k + 1] = ``'\0'``; ` `            ``fc = fc - 1; ` `            ``i = i - 1; ` `            ``l = 0; ` `        ``} ` `        ``if` `(i == fc) ` `        ``{ ` `            ``i = -1; ` `        ``} ` `        ``if` `(fc == 0)  ` `        ``{ ` `            ``break``; ` `        ``} ` `        ``l++; ` `    ``} ` ` `  `    ``// Print the results ` `    ``if` `(f == ``'e'``) ` `        ``cout << q <<``" is ENEMY to "` `<< w; ` `    ``else` `if` `(f == ``'f'``) ` `        ``cout << q <<``" is FRIEND to "``<

## C

 `// C program to implement FLAMES game ` ` `  `#include ` `#include ` ` `  `// Function to find out the flames result ` `void` `flame(``char``* a, ``char``* b) ` `{ ` `    ``int` `i, j, k, l = 1, n, m, sc = 0, tc, rc = 0, fc = 5; ` `    ``char` `q, w, c; ` `    ``char` `f[] = ``"flames"``; ` ` `  `    ``strcpy``(q, a); ` `    ``strcpy``(w, b); ` `    ``n = ``strlen``(a); ` `    ``m = ``strlen``(b); ` `    ``tc = n + m; ` ` `  `    ``for` `(i = 0; i < n; i++) { ` `        ``c = a[i]; ` `        ``for` `(j = 0; j < m; j++) { ` `            ``if` `(c == b[j]) { ` `                ``a[i] = -1; ` `                ``b[j] = -1; ` `                ``sc = sc + 2; ` `                ``break``; ` `            ``} ` `        ``} ` `    ``} ` ` `  `    ``rc = tc - sc; ` ` `  `    ``for` `(i = 0;; i++) { ` `        ``if` `(l == (rc)) { ` `            ``for` `(k = i; f[k] != ``'\0'``; k++) { ` `                ``f[k] = f[k + 1]; ` `            ``} ` `            ``f[k + 1] = ``'\0'``; ` `            ``fc = fc - 1; ` `            ``i = i - 1; ` `            ``l = 0; ` `        ``} ` `        ``if` `(i == fc) { ` `            ``i = -1; ` `        ``} ` `        ``if` `(fc == 0) { ` `            ``break``; ` `        ``} ` `        ``l++; ` `    ``} ` ` `  `    ``// Print the results ` `    ``if` `(f == ``'e'``) ` `        ``printf``(``"%s is ENEMY to %s "``, q, w); ` `    ``else` `if` `(f == ``'f'``) ` `        ``printf``(``"%s is FRIEND to %s "``, q, w); ` `    ``else` `if` `(f == ``'m'``) ` `        ``printf``(``"%s is going to MARRY %s"``, q, w); ` `    ``else` `if` `(f == ``'l'``) ` `        ``printf``(``"%s is in LOVE with %s "``, q, w); ` `    ``else` `if` `(f == ``'a'``) ` `        ``printf``(``"%s has more AFFECTION on %s "``, q, w); ` `    ``else` `        ``printf``(``"%s and %s are SISTERS/BROTHERS "``, q, w); ` `} ` ` `  `// Driver code ` `int` `main() ` `{ ` ` `  `    ``char` `a[] = ``"AJAY"``; ` `    ``char` `b[] = ``"PRIYA"``; ` ` `  `    ``flame(a, b); ` `} `

## Python3

 `# Python3 program to implement FLAMES game ` ` `  `# Function to find out the flames result ` `def` `flame(a, b): ` `    ``l, sc ``=` `1``, ``0` `    ``rc, fc ``=` `0``, ``5` `    ``f ``=` `"flames"` `    ``f ``=` `[i ``for` `i ``in` `f] ` `    ``q ``=` `"".join(a) ` `    ``w ``=` `"".join(b) ` `     `  `    ``# print(q, w) ` `    ``n ``=` `len``(a) ` `    ``m ``=` `len``(b) ` `    ``tc ``=` `n ``+` `m ` `    ``for` `i ``in` `range``(n): ` `        ``c ``=` `a[i] ` `        ``for` `j ``in` `range``(m): ` `            ``if` `(c ``=``=` `b[j]): ` `                ``a[i] ``=` `-``1` `                ``b[j] ``=` `-``1` `                ``sc ``=` `sc ``+` `2` `                ``break` ` `  `    ``rc ``=` `tc ``-` `sc ` `    ``i ``=` `0` ` `  `    ``while` `(i): ` `        ``if` `(l ``=``=` `(rc)): ` `            ``for` `k ``in` `range``(i,``len``(f)): ` `                ``f[k] ``=` `f[k ``+` `1``] ` `            ``f[k ``+` `1``] ``=` `'\0'` `            ``fc ``=` `fc ``-` `1` `            ``i ``=` `i ``-` `1` `            ``l ``=` `0` `        ``if` `(i ``=``=` `fc): ` `            ``i ``=` `-``1` `        ``if` `(fc ``=``=` `0``): ` `            ``break` `        ``l ``+``=` `1` `        ``i ``+``=` `1` ` `  `    ``# Print the results ` `    ``if` `(f[``0``] ``=``=` `'e'``): ` `        ``print``(q, ``"is ENEMY to"``, w) ` `    ``elif` `(f[``0``] ``=``=` `'f'``): ` `        ``print``(q, ``"is FRIEND to"``, w) ` `    ``elif` `(f[``0``] ``=``=` `'m'``): ` `        ``print``(q, ``"is going to MARRY"``, w) ` `    ``elif` `(f[``0``] ``=``=` `'l'``): ` `        ``print``(q, ``"is in LOVE with"``, w) ` `    ``elif` `(f[``0``] ``=``=` `'a'``): ` `        ``print``(q, ``"has more AFFECTION on"``, w) ` `    ``else``: ` `        ``print``(q, ``"and"``, w, ``"are SISTERS/BROTHERS "``) ` ` `  `# Driver code ` `a ``=` `"AJAY"` `b ``=` `"PRIYA"` `a ``=` `[i ``for` `i ``in` `a] ` `b ``=` `[j ``for` `j ``in` `b] ` ` `  `# print(a,b) ` `flame(a, b) ` ` `  `# This code is contributed by Mohit Kumar `

Output:

```AJAY is FRIEND to PRIYA
```

Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.

My Personal Notes arrow_drop_up Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. 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.

Article Tags :
Practice Tags :

4

Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.