Professional Documents
Culture Documents
FLAMES Using C
FLAMES Using C
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.
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.
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'.
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++;
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.
string a="flames";
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 *new1;
new1=new node;
new1->data=a;
new1->next=NULL;
new1->prev=NULL;
if(top==NULL)
top=new1;
temp=top;
temp->next=new1;
new1->prev=temp;
temp=new1;
return top;
Then, insert the " ames" string into the doubly linked list by characterwise.
int count1,flag=0;
for(int i=0;a[i]!='\0';i++)
top=ins(a[i]);
void check(int j)
int count1,flag=0;
for(int i=0;a[i]!='\0';i++)
top=ins(a[i]);
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;
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;
{ case 'e':cout<<"ENEMY:(";
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.
https://github.com/naveeen684/Flames-code-using-C-/tree/master