340 - Master-Mind Hints
Moderator: Board moderators
-
- Guru
- Posts: 1080
- Joined: Thu Dec 19, 2002 7:37 pm
340 - WA. Why?
Why WA?
#include <stdio.h>
const int MAX = 1001;
int gameno,i,j,n;
int code[MAX],guess[MAX],match[MAX];
int strong,weak;
int main(void)
{
gameno = 0;
while(scanf("%d",&n),n!=0)
{
for(i=0;i<n;i++)
scanf("%d",&code[i]);
printf("Game %d:\n", ++gameno);
while(1)
{
for(i=0;i<n;i++)
scanf("%d",&guess[i]);
if (!guess[0]) break;
for(i=0;i<n;i++)
if (guess[i] == code[i]) match[i] = 1; // strong match
else match[i] = 0; // empty
for(i=0;i<n;i++)
if (!match[i])
for(j=0;j<n;j++)
if (!match[j] && (code[i] == guess[j])) match[i] = 2; // weak match
strong = weak = 0;
for(i=0;i<n;i++)
{
if (match[i] == 1) strong++;
if (match[i] == 2) weak++;
}
printf(" (%d,%d)\n",strong,weak);
}
}
return 0;
}
#include <stdio.h>
const int MAX = 1001;
int gameno,i,j,n;
int code[MAX],guess[MAX],match[MAX];
int strong,weak;
int main(void)
{
gameno = 0;
while(scanf("%d",&n),n!=0)
{
for(i=0;i<n;i++)
scanf("%d",&code[i]);
printf("Game %d:\n", ++gameno);
while(1)
{
for(i=0;i<n;i++)
scanf("%d",&guess[i]);
if (!guess[0]) break;
for(i=0;i<n;i++)
if (guess[i] == code[i]) match[i] = 1; // strong match
else match[i] = 0; // empty
for(i=0;i<n;i++)
if (!match[i])
for(j=0;j<n;j++)
if (!match[j] && (code[i] == guess[j])) match[i] = 2; // weak match
strong = weak = 0;
for(i=0;i<n;i++)
{
if (match[i] == 1) strong++;
if (match[i] == 2) weak++;
}
printf(" (%d,%d)\n",strong,weak);
}
}
return 0;
}
340 Compile Error
I can't understand why I got a compile error, this is my code:
import java.io.IOException;
import java.util.StringTokenizer;
/**
* Solucion al problema 340 Master-Mind Hints.
* @author Gabriel Rivera Safadi
*/
class Main {
static String readLine() {
int car = -1;
String s = "";
try {
while (true) {
car = System.in.read();
if (car == '\n' || car < 0)
break;
if (car != 13)
s = s + (char)car;
}
} catch (IOException e) {
return null;
}
if (s.length() == 0)
return null;
return s;
}
static boolean ceros(int v[], int n) {
int cont = 0;
for (int i = 0; i < n; i++) {
if (v == 0)
cont++;
}
if (cont == n)
return true;
return false;
}
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
String s;
int game = 1;
while (!(s = readLine()).equals("0")) {
System.out.println("Game "+game+":");
game++;
int n = Integer.parseInt(s);
int v[] = new int[n];
StringTokenizer st = new StringTokenizer(readLine());
for (int i = 0; i < n; i++)
v = Integer.parseInt(st.nextToken());
int w[] = new int[n];
while (true) {
int v2[] = new int[n];
for (int i = 0; i < n; i++)
v2 = v;
st = new StringTokenizer(readLine());
for (int i = 0; i < n; i++)
w = Integer.parseInt(st.nextToken());
if (ceros(w,n))
break;
int c1 = 0;
int c2 = 0;
for (int i = 0; i < n; i++) {
if (v2 == w) {
v2 = 0;
w = 0;
c1++;
}
}
for (int i = 0; i < n; i++) {
for (int j = 0; j < n && v2 != 0; j++) {
if (v2[i] == w[j] && i != j) {
v2[i] = 0;
w[j] = 0;
c2++;
}
}
}
System.out.println(" ("+c1+","+c2+")");
}
}
}
}
Somebody please help me.
Gabox.
import java.io.IOException;
import java.util.StringTokenizer;
/**
* Solucion al problema 340 Master-Mind Hints.
* @author Gabriel Rivera Safadi
*/
class Main {
static String readLine() {
int car = -1;
String s = "";
try {
while (true) {
car = System.in.read();
if (car == '\n' || car < 0)
break;
if (car != 13)
s = s + (char)car;
}
} catch (IOException e) {
return null;
}
if (s.length() == 0)
return null;
return s;
}
static boolean ceros(int v[], int n) {
int cont = 0;
for (int i = 0; i < n; i++) {
if (v == 0)
cont++;
}
if (cont == n)
return true;
return false;
}
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
String s;
int game = 1;
while (!(s = readLine()).equals("0")) {
System.out.println("Game "+game+":");
game++;
int n = Integer.parseInt(s);
int v[] = new int[n];
StringTokenizer st = new StringTokenizer(readLine());
for (int i = 0; i < n; i++)
v = Integer.parseInt(st.nextToken());
int w[] = new int[n];
while (true) {
int v2[] = new int[n];
for (int i = 0; i < n; i++)
v2 = v;
st = new StringTokenizer(readLine());
for (int i = 0; i < n; i++)
w = Integer.parseInt(st.nextToken());
if (ceros(w,n))
break;
int c1 = 0;
int c2 = 0;
for (int i = 0; i < n; i++) {
if (v2 == w) {
v2 = 0;
w = 0;
c1++;
}
}
for (int i = 0; i < n; i++) {
for (int j = 0; j < n && v2 != 0; j++) {
if (v2[i] == w[j] && i != j) {
v2[i] = 0;
w[j] = 0;
c2++;
}
}
}
System.out.println(" ("+c1+","+c2+")");
}
}
}
}
Somebody please help me.
Gabox.
Re: 340 Mastermind
I have no idea why I am getting WA
it passes all the I/O given in the board but still WA
please someone check
here is the code:
pls help 
it passes all the I/O given in the board but still WA
please someone check
here is the code:
Code: Select all
Removed after AC

Last edited by abid_iut on Mon Dec 29, 2008 8:07 pm, edited 3 times in total.
i love to wait... wait for better... and better will come...
http://akanoi.webs.com/
http://akanoi.webs.com/
-
- New poster
- Posts: 32
- Joined: Sat Dec 29, 2007 9:08 pm
- Location: CSEDU , Dhaka
- Contact:
Re: 340 Mastermind
just change
to
Good luck 
Code: Select all
if(secret[i]=='#' && guess[i]=='#')continue;
Code: Select all
if(secret[i]=='#' && guess[j]=='#')continue;

A learner......
Re: 340 Mastermind
Thanks a lot
it was a silly mistake
anyway got AC
thanks
it was a silly mistake

anyway got AC
thanks
i love to wait... wait for better... and better will come...
http://akanoi.webs.com/
http://akanoi.webs.com/
-
- Experienced poster
- Posts: 136
- Joined: Sat Nov 29, 2008 8:01 am
- Location: narayangong,bangladesh.
- Contact:
WA: 340 Mastermind
whats wrong with my code.
WA.
#include<stdio.h>
int main()
{
int sec[10]; // secret code
int gue[10]; //guess code
int temp[10];
int n,strmatch,wkmatch;
int i,zero;
int j,counter=1;;
//freopen("input.txt","r",stdin);
// freopen("output.txt","w",stdout);
while(scanf("%d",&n)==1)
{
if(n==0)
break;
for(i=0;i<n;i++)
{
scanf("%d",&sec);
}
printf("Game %d:\n",counter);
while(1)
{
for(i=0;i<n;i++)
{
temp=sec;
}
strmatch=0;
wkmatch=0;
zero=0;
for(j=0;j<n;j++)
{
scanf("%d",&gue[j]);
if(gue[j]==0)
zero=zero+1;
}
if(zero==n)
break;
for(i=0;i<n;i++)
{
if(gue==temp)
{
strmatch=strmatch+1;
gue=-10;
temp=-100;
}
}
printf(" (%d,",strmatch);
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
if(gue==temp[j])
{
//printf("i;%d j:%d\n",i,j);
wkmatch=wkmatch+1;
temp[j]=-50;
break;
}
}
}
printf("%d)\n",wkmatch);
}
counter++;
}
return 0;
}
WA.
#include<stdio.h>
int main()
{
int sec[10]; // secret code
int gue[10]; //guess code
int temp[10];
int n,strmatch,wkmatch;
int i,zero;
int j,counter=1;;
//freopen("input.txt","r",stdin);
// freopen("output.txt","w",stdout);
while(scanf("%d",&n)==1)
{
if(n==0)
break;
for(i=0;i<n;i++)
{
scanf("%d",&sec);
}
printf("Game %d:\n",counter);
while(1)
{
for(i=0;i<n;i++)
{
temp=sec;
}
strmatch=0;
wkmatch=0;
zero=0;
for(j=0;j<n;j++)
{
scanf("%d",&gue[j]);
if(gue[j]==0)
zero=zero+1;
}
if(zero==n)
break;
for(i=0;i<n;i++)
{
if(gue==temp)
{
strmatch=strmatch+1;
gue=-10;
temp=-100;
}
}
printf(" (%d,",strmatch);
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
if(gue==temp[j])
{
//printf("i;%d j:%d\n",i,j);
wkmatch=wkmatch+1;
temp[j]=-50;
break;
}
}
}
printf("%d)\n",wkmatch);
}
counter++;
}
return 0;
}
Life is more complicated than algorithm.
http://felix-halim.net/uva/hunting.php?id=32359
For Hints: http://salimsazzad.wordpress.com
http://felix-halim.net/uva/hunting.php?id=32359
For Hints: http://salimsazzad.wordpress.com
WA in 340-MasterMind Hints
Hello Sir,
Don't know why I am getting WA for this question by uva judge, it seems no error to me and my head is stuck off with the frustration to find the error.Please help me out..
My code :-
Thanks for quick reply..
Don't know why I am getting WA for this question by uva judge, it seems no error to me and my head is stuck off with the frustration to find the error.Please help me out..

My code :-
Code: Select all
REMOVED AFTER AC.

Last edited by avinashse on Tue Feb 28, 2012 11:09 am, edited 1 time in total.
-
- Guru
- Posts: 5947
- Joined: Thu Sep 01, 2011 9:09 am
- Location: San Jose, CA, USA
Re: WA in 340-MasterMind Hints
Try input:
4
1 3 5 5
5 5 6 6
0 0 0 0
0
4
1 3 5 5
5 5 6 6
0 0 0 0
0
Check input and AC output for thousands of problems on uDebug!
-
- Experienced poster
- Posts: 148
- Joined: Sun Jul 13, 2014 4:32 am
- Location: Rangpur, Bangladesh
Re: 340 - Master-Mind Hints
Can anybody please explain the sample output clearly? I didn't understand how to determine i and j for each guess.
For each guess for the given sample input in problem, explain me how each match(i, j) in output is generated.
For each guess for the given sample input in problem, explain me how each match(i, j) in output is generated.
Md. Shahidul Islam
Dept. of CSE at Begum Rokeya University, Rangpur, Bangladesh
UVa id: http://uhunt.felix-halim.net/id/438420
My facebook account,
Email me: shahidul.cse.brur@gmail.com
Dept. of CSE at Begum Rokeya University, Rangpur, Bangladesh
UVa id: http://uhunt.felix-halim.net/id/438420
My facebook account,
Email me: shahidul.cse.brur@gmail.com
-
- Guru
- Posts: 5947
- Joined: Thu Sep 01, 2011 9:09 am
- Location: San Jose, CA, USA
Re: 340 - Master-Mind Hints
Check input and AC output for thousands of problems on uDebug!
-
- Experienced poster
- Posts: 148
- Joined: Sun Jul 13, 2014 4:32 am
- Location: Rangpur, Bangladesh
Re: 340 - Master-Mind Hints
Thanks ! 

Md. Shahidul Islam
Dept. of CSE at Begum Rokeya University, Rangpur, Bangladesh
UVa id: http://uhunt.felix-halim.net/id/438420
My facebook account,
Email me: shahidul.cse.brur@gmail.com
Dept. of CSE at Begum Rokeya University, Rangpur, Bangladesh
UVa id: http://uhunt.felix-halim.net/id/438420
My facebook account,
Email me: shahidul.cse.brur@gmail.com