Program to implement FLAMES game

09 Jun, 2021
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: 
Take the two names.
Remove the common characters with their respective common occurrences.
Get the count of the characters that are left .
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 .
 
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
Python3
Javascript
// C++ program to implement FLAMES game#include <bits/stdc++.h>using namespace std; // Function to find out the flames resultvoid flame(char* a, char* b){    int i, j, k, l = 1, n, m, sc = 0, tc, rc = 0, fc = 5;    char q[25], w[25], 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[0] == 'e')        cout << q <<" is ENEMY to " << w;    else if (f[0] == 'f')        cout << q <<" is FRIEND to "<<w;    else if (f[0] == 'm')        cout << q <<" is going to MARRY "<<w;    else if (f[0] == 'l')        cout << q <<" is in LOVE with "<<w;    else if (f[0] == 'a')        cout << q <<" has more AFFECTION on "<<w;    else        cout << q << " and "<< w <<" are SISTERS/BROTHERS ";} // Driver codeint main(){    char a[] = "AJAY";    char b[] = "PRIYA";     flame(a, b);} // This code is contributed by SHUBHMASINGH10
// C program to implement FLAMES game #include <stdio.h>#include <string.h> // Function to find out the flames resultvoid flame(char* a, char* b){    int i, j, k, l = 1, n, m, sc = 0, tc, rc = 0, fc = 5;    char q[25], w[25], 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[0] == 'e')        printf("%s is ENEMY to %s ", q, w);    else if (f[0] == 'f')        printf("%s is FRIEND to %s ", q, w);    else if (f[0] == 'm')        printf("%s is going to MARRY %s", q, w);    else if (f[0] == 'l')        printf("%s is in LOVE with %s ", q, w);    else if (f[0] == 'a')        printf("%s has more AFFECTION on %s ", q, w);    else        printf("%s and %s are SISTERS/BROTHERS ", q, w);} // Driver codeint main(){     char a[] = "AJAY";    char b[] = "PRIYA";     flame(a, b);}
# Python3 program to implement FLAMES game # Function to find out the flames resultdef 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 codea = "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
<script>// Javascript program to implement FLAMES game // Function to find out the flames resultfunction flame(a,b){    let i, j, k, l = 1, n, m, sc = 0, tc, rc = 0, fc = 5;    let c;    let f = "flames";       let q = a.join("")    let w = b.join("")    n = a.length;    m = b.length;    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; k<f.length; 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[0] == 'e')        document.write(q+" is ENEMY to "+w);             else if (f[0] == 'f')        document.write(q+" is FRIEND to "+w);             else if (f[0] == 'm')        document.write(q+" is going to MARRY "+w);             else if (f[0] == 'l')        document.write(q+" is in LOVE with "+w);             else if (f[0] == 'a')        document.write(q+" has more AFFECTION on "+w);             else        document.write(q+" and "<+w+" are SISTERS/BROTHERS ");         } // Driver codelet a="AJAY".split("");let b= "PRIYA".split("");flame(a, b); // This code is contributed by unknown2108.</script>
AJAY is FRIEND to PRIYA
 
mohit kumar 29
SHUBHAMSINGH10
unknown2108
Picked
Strings
Strings
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Top 50 String Coding Problems for Interviews
What is Data Structure: Types, Classifications and Applications
Print all the duplicates in the input string
Print all subsequences of a string
A Program to check if strings are rotations of each other or not
String class in Java | Set 1
Find if a string is interleaved of two other strings | DP-33
Remove first and last character of a string in Java
Check if an URL is valid or not using Regular Expression
Find the smallest window in a string containing all characters of another string