Everyone of us might have played the game of FLAMES among our friends or acquaintances which represents the relationship between two persons .
As we know the general procedure of this game is :-
1.The number of uncommon letters in the names of two persons is counted , let the count be N
2.Now we start counting the letters of the word FLAMES in a circular fashion and eliminating the letters which count the same value of N (i.e. no. of uncommon letters in two names), stop this process when you are left out with a single letter and that single letter represents the relationship between those two individuals Here, each letter of the word FLAMES represents a relationship as:
1.F-Friendship
2.L-Love
3.A-Ancestors
4.M-Marriage
5.E-Enemies
Programmable logic to find last letter of the flames:-
below 'C' code snippet returns the required letter :-
#include<stdio.h>
#include<string.h>
int swap1(int,char[]);
int swap(int,char[]);
char a[200];
char b[200];
int ch(char[]);
int count=0;
void flames(int);
char f[]={"flames"};
int main()
{
char c[200];
char ch1;
int i,j;
int al,bl,l;
printf("\nEnter fullname without spaces : \n");
printf("Enter ur name : ");
scanf("%s",a);
al=ch(a);
printf("Enter name : ");
scanf("%s",b);
l=bl=ch(b);
for(i=0;i<al;i++)
{
for(j=0;j<ch(b);j++)
if(a[i]==b[j])
{
count++;
swap(j,b);
}
}
count=(l+al)-2*count;
flames(count);
return 143;
}
int swap(int n,char b[])
{
int i;
for(i=n;i<ch(b)-1;i++)
b[i]=b[i+1];
b[i]='\0';
}
int ch(char n[])
{
int i;
for(i=0;n[i]!='\0';i++);
return i;
}
int swap1(int i,char b[])
{
static int j=0;
int k=ch(b),m=0,n;
for(;;)
{
if(j>=k)
j=0;
if(m==i-1)
{
for(n=j;n<k-1;n++)
b[n]=b[n+1];
b[n]='\0';
return 0;
}
j++;
m++;
}
}
void flames(int l)
{
int i=0;
int len;
len=ch(f);
while(len!=2)
{ len=ch(f);
swap1(l,f);
}
printf("flames : %c\n",f[0]);
}
Try this out:-
Click Here to download the application.
Stay Connected...!
w'll come up with interesting programs....!
No comments: