Open In App

Program to implement FLAMES game

Improve
Improve
Improve
Like Article
Like
Save Article
Save
Share
Report issue
Report

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. 

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++ program to implement FLAMES game
#include <bits/stdc++.h>
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[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 code
int main()
{
    char a[] = "AJAY";
    char b[] = "PRIYA";
 
    flame(a, b);
}
 
// This code is contributed by SHUBHMASINGH10


C




// C program to implement FLAMES game
 
#include <stdio.h>
#include <string.h>
 
// 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[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 code
int main()
{
 
    char a[] = "AJAY";
    char b[] = "PRIYA";
 
    flame(a, b);
}


Java




// Java program for the above approach
 
import java.util.*;
 
public class FlamesGame {
 
    // Function to find out the flames result
    public static void flame(char[] a, char[] b) {
        int l = 1, sc = 0, rc = 0, fc = 5;
        String f = "flames";
        char[] flames = f.toCharArray();
        String q = new String(a);
        String w = new String(b);
 
        int n = a.length;
        int m = b.length;
        int tc = n + m;
 
        for (int i = 0; i < n; i++) {
            char c = a[i];
            for (int j = 0; j < m; j++) {
                if (c == b[j]) {
                    a[i] = b[j] = '-'; // mark the matched characters with '-'
                    sc += 2;
                    break;
                }
            }
        }
 
        rc = tc - sc;
        int i = 0;
 
        while (i >= 0) {
            if (l == rc) {
                for (int k = i; k < f.length()-1; k++) {
                    flames[k] = flames[k + 1];
                }
                flames[flames.length-1] = '0';
                fc--;
                i--;
                l = 0;
            }
            if (i == fc) {
                i = -1;
            }
            if (fc == 0) {
                break;
            }
            l++;
            i++;
        }
 
        // Print the results
        char result = flames[0];
        switch (result) {
            case 'e':
                System.out.println(q + " is ENEMY to " + w);
                break;
            case 'f':
                System.out.println(q + " is FRIEND to " + w);
                break;
            case 'm':
                System.out.println(q + " is going to MARRY " + w);
                break;
            case 'l':
                System.out.println(q + " is in LOVE with " + w);
                break;
            case 'a':
                System.out.println(q + " has more AFFECTION on " + w);
                break;
            default:
                System.out.println(q + " and " + w + " are SISTERS/BROTHERS ");
                break;
        }
    }
 
    // Driver code
    public static void main(String[] args) {
        String a = "AJAY";
        String b = "PRIYA";
        char[] charA = a.toCharArray();
        char[] charB = b.toCharArray();
 
        flame(charA, charB);
    }
}
 
// This code is contributed by codebraxnzt


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


C#




// C# program for the above approach
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
 
class HelloWorld {
     
     
    // Function to find out the flames result
    public static void flame(char[] a, char[] b) {
        int l = 1, sc = 0, rc = 0, fc = 5;
        string f = "flames";
        char[] flames = f.ToCharArray();
        string q = new string(a);
        string w = new string(b);
 
        int n = a.Length;
        int m = b.Length;
        int tc = n + m;
 
        for (int indx = 0; indx < n; indx++) {
            char c = a[indx];
            for (int j = 0; j < m; j++) {
                if (c == b[j]) {
                    a[indx] = b[j] = '-'; // mark the matched characters with '-'
                    sc += 2;
                    break;
                }
            }
        }
 
        rc = tc - sc;
        int i = 0;
 
        while (i >= 0) {
            if (l == rc) {
                for (int k = i; k < f.Length-1; k++) {
                    flames[k] = flames[k + 1];
                }
                flames[flames.Length-1] = '0';
                fc--;
                i--;
                l = 0;
            }
            if (i == fc) {
                i = -1;
            }
            if (fc == 0) {
                break;
            }
            l++;
            i++;
        }
 
        // Print the results
        char result = flames[0];
        switch (result) {
            case 'e':
                Console.WriteLine(q + " is ENEMY to " + w);
                break;
            case 'f':
                Console.WriteLine(q + " is FRIEND to " + w);
                break;
            case 'm':
                Console.WriteLine(q + " is going to MARRY " + w);
                break;
            case 'l':
                Console.WriteLine(q + " is in LOVE with " + w);
                break;
            case 'a':
                Console.WriteLine(q + " has more AFFECTION on " + w);
                break;
            default:
                Console.WriteLine(q + " and " + w + " are SISTERS/BROTHERS ");
                break;
        }
    }
     
    static void Main() {
        string a = "AJAY";
        string b = "PRIYA";
        char[] charA = a.ToCharArray();
        char[] charB = b.ToCharArray();
 
        flame(charA, charB);
    }
}
 
// The code is contributed by Arushi Jindal.


Javascript




<script>
// Javascript program to implement FLAMES game
 
// Function to find out the flames result
function 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 code
let a="AJAY".split("");
let b= "PRIYA".split("");
flame(a, b);
 
// This code is contributed by unknown2108.
</script>


Output: 

AJAY is FRIEND to PRIYA

 



Last Updated : 09 Mar, 2023
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads