Title Description Mastermind is a Two-person code breaking game which works as follows. The. RST person (the code maker) creates a sequence of n colored pegs (with duplicate colors allowed) and hides it from VI ew.
This sequence of pegs is the code.
The second person (the Code breaker) have the job of trying to determine the code maker's code and she does so by making a Series of guesses. Each guess also consists of n colored pegs. After each guess, the code maker gives the code breaker feedback about what close she is. This feedback consists of the number r and S, where
• R = The number of pegs that is identical in both color and position in the code and the
Guess,and
• S = The number of remaining pegs that is identical in color and not in the same position.
For example, if the code was BACC (where we use different letters to represent colors) and the guess was cabb, then r = 1 (t He A in the second position of both the code and the guess) and S = 2 (A B and C in the remaining three characters). Note that only one of the B's in the Guess would "match" with the one B in the code:once pegs in the code and the Guess The been "matched" with the other, they can ' t is matched with any other pegs.
Your job in this problem are to determine r and s given a code and a guess. Enter the input is a single line containing a Positi ve integer n≤50 (the length of the code) followed by-strings of length n-the? Rst of these is the code and the SEC Ond is the guess. Both code and guess is made up of upper-case alphabetic characters. Output outputs the values of R and s for the given input. Sample input Into
4 BACC Cabb
Sample output
1 2
CODE:
#include <stdio.h>
#include <string.h>
void Dele (char *p)
{
Char *i;
for (i=p+1;*i!= ';p ++,i++)
*p=*i;
*p= ' + ';
}
int main ()
{
int n,r=0,s=0,j,i;
Char *p1;
Char a[52],b[52];
while (scanf ("%d", &n)!=eof)
{
GetChar ();
for (i=0;i<n;i++)
scanf ("%c", &a[i]);
a[i]= ' + ';
GetChar ();
for (i=0;i<n;i++)
scanf ("%c", &b[i]);
b[i]= ' + ';
For (I=0;i<strlen (a); i++)
{
if (A[i]==b[i])
{
r++;
p1=&a[i];
Dele (p1);
p1=&b[i];
Dele (p1);
i--;
}
}
For (I=0;i<strlen (a); i++)
{
For (J=0;j<strlen (b); j + +)
{
if (A[i]==b[j])
{
s++;
p1=&a[i];
Dele (p1);
p1=&b[j];
Dele (p1);
j--;
i--;
}
}
}
printf ("%d%d", r,s);
}
return 0;
}
E.mastering Mastermind