## 340 - Master-Mind Hints

Moderator: Board moderators

arc16
Learning poster
Posts: 62
Joined: Sun Aug 04, 2002 1:05 am
Location: Indonesia

### 340 - Master-Mind Hints

the problem is simple, but i got WA
is there any tricky case?

arc16
Learning poster
Posts: 62
Joined: Sun Aug 04, 2002 1:05 am
Location: Indonesia
my stupid mistake
somehow i set 100 for the max size where it should be 1000

deddy one
Experienced poster
Posts: 120
Joined: Tue Nov 12, 2002 7:36 pm
I know it simple , but WA keeping me still.

Btw, where should I print "game #%d" , is it before the input or after the input??

epsilon0
Experienced poster
Posts: 112
Joined: Tue Nov 12, 2002 11:15 pm
Location: Paris, France.
deddy one it doesn't matter wether you print stuff before or after you read the input!!!
what matters is what you output... you could read all the input at once in a large buffer, or one job at a time, as you like.

this problem is not hard...think about special cases..

things like

123456789
111111111
We never perform a computation ourselves, we just hitch a ride on the great Computation that is going on already. --Tomasso Toffoli

deddy one
Experienced poster
Posts: 120
Joined: Tue Nov 12, 2002 7:36 pm
my output is

(1,0)

is it correct??
is there any other trick related to this problem?

deddy one
Experienced poster
Posts: 120
Joined: Tue Nov 12, 2002 7:36 pm
thx epsilon, your test case inspired me of another test case
which is

987654321
111111111

this is the test case I needed to find my little bug

ericpo
New poster
Posts: 1
Joined: Mon May 26, 2003 6:48 am
Contact:

### 340--help!!

I keep get WA,so is there anyone can give me some test data??

chfgress
New poster
Posts: 3
Joined: Tue Jun 03, 2003 2:55 am
I'm also having problems with WA, I tried all the input samples and some that I found in this forum... and a lot more... and it was always OK.

Do you have more input samples?

When you have a good reply (I know that i didn't help you, but), could you let me know?

Thx,
Carlos

chunyi81
A great helper
Posts: 293
Joined: Sat Jun 21, 2003 4:19 am
Location: Singapore

### 340 why WA?

[java]import java.io.*;
import java.util.*;
class Main {

{
byte lin[] = new byte [maxLg];
int lg = 0, car = -1;
String line = "";

try
{
while (lg < maxLg)
{
if ((car < 0) || (car == '\n')) break;
lin [lg++] += car;
}
}

catch (IOException e)
{
return (null);
}

if ((car < 0) && (lg == 0)) return (null);
return (new String (lin, 0, lg));
}

public static void main(String[] args) {

int games = 1;

while(line.charAt(0) != '0') {

System.out.println("Game " + games + ":");

StringTokenizer st = new StringTokenizer(line);
int len = Integer.parseInt(st.nextToken());
int[] secret = new int[len];
int[] guess = new int[len];

for (int i = 0;i < len;i++)
secret = Integer.parseInt(st.nextToken());

for (int i = 0;i < len;i++)
guess = Integer.parseInt(st.nextToken());

while(guess[0] != 0) {

int strong = 0;
int weak = 0;
boolean[] match1 = new boolean[len];
boolean[] match2 = new boolean[len];

for (int i = 0;i < len;i++) {

if (guess == secret) {
match1 = true;
match2 = true;
strong++;
}

}

for (int j = 0;j < len;j++) {

if (!match2[j]) {

for (int k = 0;k < len;k++) {

if (!match1[k] && (guess[j] == secret[k])) {
match1[k] = true;
match2[j] = true;
weak++;
break;
}

}

}

}

System.out.println(" (" + strong + "," + weak + ")");

for (int i = 0;i < len;i++)
guess = Integer.parseInt(st.nextToken());

}

games++;

}

}

}[/java]

Why the above code gives WA? It works with the special cases mentioned in this forum, and also works with the sample input.

Observer
Guru
Posts: 570
Joined: Sat May 10, 2003 4:20 am
Location: Hong Kong

### Re: 340 why WA?

Note that "The maximum value for N will be 1000"!!!

So the line may contain more than 255 characters!!
Last edited by Observer on Mon Jul 07, 2003 10:57 am, edited 1 time in total.
7th Contest of Newbies
Date: December 31st, 2011 (Saturday)
Time: 12:00 - 16:00 (UTC)
URL: http://uva.onlinejudge.org

chunyi81
A great helper
Posts: 293
Joined: Sat Jun 21, 2003 4:19 am
Location: Singapore

### Re: 340 why WA?

Observer wrote:I know nothing about Java...

Note that "The maximum value for N will be 1000"!!!
chunyi81 wrote:[java]import java.io.*;
import java.util.*;
class Main {

{
byte lin[] = new byte [maxLg];
int lg = 0, car = -1;
String line = "";

try
{
while (lg < maxLg)
{
if ((car < 0) || (car == '\n')) break;
lin [lg++] += car;
}
}

catch (IOException e)
{
return (null);
}

if ((car < 0) && (lg == 0)) return (null);
return (new String (lin, 0, lg));
}

public static void main(String[] args) {

int games = 1;

while(line.charAt(0) != '0') {

System.out.println("Game " + games + ":");

StringTokenizer st = new StringTokenizer(line);
int len = Integer.parseInt(st.nextToken());
int[] secret = new int[len];
int[] guess = new int[len];

for (int i = 0;i < len;i++)
secret = Integer.parseInt(st.nextToken());

for (int i = 0;i < len;i++)
guess = Integer.parseInt(st.nextToken());

while(guess[0] != 0) {

int strong = 0;
int weak = 0;
boolean[] match1 = new boolean[len];
boolean[] match2 = new boolean[len];

for (int i = 0;i < len;i++) {

if (guess == secret) {
match1 = true;
match2 = true;
strong++;
}

}

for (int j = 0;j < len;j++) {

if (!match2[j]) {

for (int k = 0;k < len;k++) {

if (!match1[k] && (guess[j] == secret[k])) {
match1[k] = true;
match2[j] = true;
weak++;
break;
}

}

}

}

System.out.println(" (" + strong + "," + weak + ")");

for (int i = 0;i < len;i++)
guess = Integer.parseInt(st.nextToken());

}

games++;

}

}

}[/java]

Why the above code gives WA? It works with the special cases mentioned in this forum, and also works with the sample input.

I know the max value of N is 1000. I used ReadLn(255) where ReadLn is a method defined to read from stdin(standard input) in Java. The number 255 means the max number of characters read per line.

Could u take a look at my code for problem 320 please? I could have misunderstood the problem 320. Thanks.

chunyi81
A great helper
Posts: 293
Joined: Sat Jun 21, 2003 4:19 am
Location: Singapore

### 340 why WA

Never mind, i found my mistake and got AC already. Some of the ReadLn statements I had to increase the max length of the string read to 2100 because the input for the code can be up to 1000(numbers in a code of length 1000) + 999(spaces) = 1999 characters. Thanks.

dt96hasv
New poster
Posts: 5
Joined: Wed Oct 20, 2004 9:27 am
Location: Gothenburg
Contact:

### 340 - Master-Mind hints

Hi, I have been playing around with this problem for a while, and cannot find any example where my program is wrong, but still it is since the judge won't accept it

[c]
#include <stdio.h>

int min(int a, int b){
if(a < b)
return a;
return b;
}

int main(){

int N,g=0,i,s,w;

char facit[1000];
char guess[1000];

int f_freq[10],g_freq[10];

while( scanf("%d",&N) == 1 && N > 0){
g++;
printf("Game %d:\n",g);

for(i = 0; i < N ; i++){
scanf("%d",&facit);
}

while(1){
for(i = 0; i < N ; i++){
scanf("%d",&guess);
}

if(guess[0] == 0) break;

s = w = 0;

[SNIP] Don't want to spoil all the fun [/SNIP]

printf(" (%d,%d)\n",s,w);
}
}
}
[/c]
On an input file like

Code: Select all

``````4
1 3 5 5
1 1 2 3
4 3 3 5
6 5 5 1
6 1 3 5
1 3 5 5
0 0 0 0
10
1 2 2 2 4 5 6 6 6 9
1 2 3 4 5 6 7 8 9 1
1 1 2 2 3 3 4 4 5 5
1 2 1 3 1 5 1 6 1 9
1 2 2 5 5 5 6 6 6 7
0 0 0 0 0 0 0 0 0 0
9
1 2 3 4 5 6 7 8 9
1 1 1 1 1 1 1 1 1
0 0 0 0 0 0 0 0 0
9
1 1 1 1 1 1 1 1 1
1 2 3 4 5 6 7 8 9
9 8 7 6 5 4 3 2 1
0 0 0 0 0 0 0 0 0
3
1 2 3
3 2 1
1 1 1
2 2 2
3 3 3
1 2 3
2 1 2
4 1 2
2 1 2
3 3 1
1 2 2
0 0 0
1
2
3
2
1
0
2
2 2
1 2
1 3
3 1
2 1
2 2
0 0
4
1 2 1 2
2 1 1 2
2 1 2 1
1 2 2 1
1 3 3 1
3 1 3 1
0 0 0 0
0
``````

Code: Select all

``````Game 1:
(1,1)
(2,0)
(1,2)
(1,2)
(4,0)
Game 2:
(2,4)
(3,2)
(5,0)
(7,0)
Game 3:
(1,0)
Game 4:
(1,0)
(1,0)
Game 5:
(1,2)
(1,0)
(1,0)
(1,0)
(3,0)
(0,2)
(0,2)
(0,2)
(0,2)
(2,0)
Game 6:
(0,0)
(1,0)
(0,0)
Game 7:
(1,0)
(0,0)
(0,0)
(1,0)
(2,0)
Game 8:
(2,2)
(0,4)
(2,2)
(1,1)
(0,2)
``````
Which is the expected (?) my question is if someone could give me a counterexample?
Sorry for the long post, just felt like it would be fun to find the error...

/Hans
Last edited by dt96hasv on Wed Oct 20, 2004 1:20 pm, edited 1 time in total.

little joey
Guru
Posts: 1080
Joined: Thu Dec 19, 2002 7:37 pm
Change the type of facit[] and guess[] to int and you'll get accepted.

You read the values of the arrays using scanf("%d",&guess), but since you specify "%d", scanf() will always put 4 bytes (the size of an int) into four consecutive places starting at the address you specified.

dt96hasv
New poster
Posts: 5
Joined: Wed Oct 20, 2004 9:27 am
Location: Gothenburg
Contact:
Gosh, that is soo sloppy of me.
I could have spent days looking for that bug, thanx a lot!