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:
- 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++
#include <bits/stdc++.h>
using namespace std;
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++;
}
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 " ;
}
int main()
{
char a[] = "AJAY" ;
char b[] = "PRIYA" ;
flame(a, b);
}
|
C
#include <stdio.h>
#include <string.h>
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++;
}
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);
}
int main()
{
char a[] = "AJAY" ;
char b[] = "PRIYA" ;
flame(a, b);
}
|
Java
import java.util.*;
public class FlamesGame {
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] = '-' ;
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++;
}
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 ;
}
}
public static void main(String[] args) {
String a = "AJAY" ;
String b = "PRIYA" ;
char [] charA = a.toCharArray();
char [] charB = b.toCharArray();
flame(charA, charB);
}
}
|
Python3
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)
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
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 " )
a = "AJAY"
b = "PRIYA"
a = [i for i in a]
b = [j for j in b]
flame(a, b)
|
C#
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
class HelloWorld {
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] = '-' ;
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++;
}
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);
}
}
|
Javascript
<script>
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++;
}
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 " );
}
let a= "AJAY" .split( "" );
let b= "PRIYA" .split( "" );
flame(a, b);
</script>
|
Output:
AJAY is FRIEND to PRIYA
Last Updated :
09 Mar, 2023
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...