Page 2 of 2
Posted: Wed Oct 20, 2004 12:26 pm
We can only learn by making mistakes! The more irritating the mistake is, the more we have learned...

Could you please remove the essential parts of the code in your previous post? It's a spoiler now.

Posted: Wed Oct 20, 2004 1:21 pm
little joey wrote:We can only learn by making mistakes! The more irritating the mistake is, the more we have learned...

Could you please remove the essential parts of the code in your previous post? It's a spoiler now.
Done!

340 - WA. Why?

Posted: Wed Mar 23, 2005 7:06 pm
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;
}

340 Compile Error

Posted: Fri May 26, 2006 3:24 am
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.
*/
class Main {

int car = -1;
String s = "";
try {
while (true) {
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;
System.out.println("Game "+game+":");
game++;
int n = Integer.parseInt(s);
int v[] = new int[n];
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;
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+")");
}
}
}

}

Gabox.

Re: 340 Mastermind

Posted: Mon Dec 29, 2008 7:59 am
I have no idea why I am getting WA
it passes all the I/O given in the board but still WA
here is the code:

Code: Select all

``````Removed after AC
``````
pls help

Re: 340 Mastermind

Posted: Mon Dec 29, 2008 2:29 pm
just change

Code: Select all

``````if(secret[i]=='#' && guess[i]=='#')continue;
``````
to

Code: Select all

``````if(secret[i]=='#' && guess[j]=='#')continue;
``````
Good luck

Re: 340 Mastermind

Posted: Mon Dec 29, 2008 8:09 pm
Thanks a lot
it was a silly mistake
anyway got AC
thanks

WA: 340 Mastermind

Posted: Sat Jan 31, 2009 9:08 pm
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 in 340-MasterMind Hints

Posted: Mon Feb 27, 2012 9:36 am
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 :-

Code: Select all

``````REMOVED AFTER AC.
``````

Re: WA in 340-MasterMind Hints

Posted: Tue Feb 28, 2012 3:53 am
Try input:
4
1 3 5 5
5 5 6 6
0 0 0 0
0

Re: 340 - Master-Mind Hints

Posted: Tue Dec 02, 2014 8:29 am
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.

Re: 340 - Master-Mind Hints

Posted: Tue Dec 02, 2014 9:47 pm

Re: 340 - Master-Mind Hints

Posted: Wed Dec 03, 2014 6:32 am
Thanks !