FLAMES Using C

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 8

instructables

FLAMES Using C++

by Naveendata

Hello friends, We all know about the ames game. Lol, It's one of the funniest games that made our childhood
more happier. In this instructable, we are going to see how to code a ames program using the C++ language.

Step 1: Concepts Used

Here I used the Circular doubly linked list.

Step 2: Main Function

FLAMES Using C++: Page 1


int main()

string name1,name2;
int n1,n2;
cout<<"ENTER FIRST NAME:";
getline(cin,name1);
cout<<"ENTER SECOND NAME:";
getline(cin,name2);

First, we need to get the two names with space so I use the getline() function to get the string with space.

Step 3: How to Omit Special Characters?

void emit(string &a)

for(int i=0;a[i]!='\0';i++)

if(a[i]>='a'&&a[i]<='z') {}

else if(a[i]>='A'&&a[i]<='Z'){}

else

a[i]='0';

}
}

Now, we need to remove the special characters like &, $, ' ' ...etc. By using this function we removed all characters
other than alphabets. Here, instead of removing, I replace it with '0'.

Step 4: Removing Same Characters

FLAMES Using C++: Page 2


for(i=0;name1[i]!='\0';i++)

for(j=0;name2[j]!='\0';j++)

if((name1[i]==name2[j] || name1[i]==name2[j]+32))

name1[i]='0';

name2[j]='0';

break;

It is the rst step of the ames game, That we need to remove the same characters that present in the two names.
This code snippet helps us to replace the same characters by '0' and it also works well even it contains both the
uppercase and lower case. The break statement helps us to avoid the removal of repeating characters.

j=0;<br>for(i=0;name1[i]!='\0';i++)

if(name1[i]!='0')

j++;

for(i=0;name2[i]!='\0';i++)

if(name2[i]!='0')

j++;

if(j==0)<br> cout<<"NO FLAMES";

Here, we remove all '0's that are present in both names. Therefore, nally, all the same, characters are removed.
Then the j is incremented that it is the count of the letters that are present in both names after removing the same
characters. Now we need to check whether it contains at least one character or not. To make the code e cient we
need to tell there is no possibility to play the ames game if it contains no unique characters.

FLAMES Using C++: Page 3


Step 5: Creating Circular Doubly Linked List

string a="flames";

First, create a global string that contains " ames".

typedef struct node<br>{

char data;

node *next,*prev;

}node;

node *top=NULL,*temp;

Now, create a structure that contains a character data, next address pointer, and previous address pointer.

Then create a pointer that points towards the top of the linked list.

node* ins(char a)<br>{

node *new1;

new1=new node;

new1->data=a;

new1->next=NULL;

new1->prev=NULL;

if(top==NULL)

top=new1;

temp=top;

FLAMES Using C++: Page 4


else

temp->next=new1;

new1->prev=temp;

temp=new1;

return top;

Then, insert the " ames" string into the doubly linked list by characterwise.

void check(int j)<br>{

int count1,flag=0;

for(int i=0;a[i]!='\0';i++)

top=ins(a[i]);

Step 6: Code to Play the Flames

void check(int j)

int count1,flag=0;

for(int i=0;a[i]!='\0';i++)

top=ins(a[i]);

FLAMES Using C++: Page 5


node *cur=top,*prev1;

temp->next=top;

top->prev=temp;

while(1)

count1=1;

while(count1<j)

cur=cur->next;

count1++;

node *temp1=cur;

prev1=cur->prev;

cur->prev->next=cur->next;

cur->next->prev=cur->prev;

temp1->next=NULL;

free(temp1);

cur=prev1->next;

node *test=cur;

FLAMES Using C++: Page 6


if(test->data==test->next->data)

break;

we need to run the circular list that is the " ames" string according to the count of unique characters. Then we need
to remove the character in " ames" that coincide with the count. We should realize the usage of a doubly linked list
in this code snippet. It helps a lot to remove a particular character. It removes continuously. Until it reaches the
condition that the same characters come repeatedly.

if(test->data==test->next->data)
break;

Step 7: Tell the Result

FLAMES Using C++: Page 7


switch(cur->data) break;

{ case 'e':cout<<"ENEMY:(";

case 'f ':cout<<"FRIENDS&&"; break;

break; case 's':cout<<"SIBLING";

case 'l':cout<<"LOVE<3"; break; }

break; Use this switch statement to tell the nal result that is
the last character remains after removing all other
case 'a':cout<<"AFFECTION$"; characters according to the count.

break; Now you can play ames easily by just entering the
names, It's funny right. Play this game using your
case 'm':cout<<"MARRIAGE:)"; friend's names and make them angry LOL. Thank you.

Step 8: Code for Flames

The complete code for FLAMES is available here,

https://github.com/naveeen684/Flames-code-using-C-/tree/master

FLAMES Using C++: Page 8

You might also like