340 - Master-Mind Hints

All about problems in Volume 3. If there is a thread about your problem, please use it. If not, create one with its number in the subject.

Moderator: Board moderators

User avatar
little joey
Guru
Posts: 1080
Joined: Thu Dec 19, 2002 7:37 pm

Post by little joey » 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.

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

Post by dt96hasv » 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!

medv
Learning poster
Posts: 85
Joined: Sun Jul 14, 2002 1:17 pm

340 - WA. Why?

Post by medv » 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;
}

gabox
New poster
Posts: 2
Joined: Fri May 26, 2006 3:06 am

340 Compile Error

Post by gabox » 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.
* @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.

abid_iut
Learning poster
Posts: 82
Joined: Wed Jul 16, 2008 7:34 am

Re: 340 Mastermind

Post by abid_iut » 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
please someone check
here is the code:

Code: Select all

Removed after AC
pls help :(
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/

shiplu_1320
New poster
Posts: 32
Joined: Sat Dec 29, 2007 9:08 pm
Location: CSEDU , Dhaka
Contact:

Re: 340 Mastermind

Post by shiplu_1320 » 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 :)
A learner......

abid_iut
Learning poster
Posts: 82
Joined: Wed Jul 16, 2008 7:34 am

Re: 340 Mastermind

Post by abid_iut » Mon Dec 29, 2008 8:09 pm

Thanks a lot
it was a silly mistake :wink:
anyway got AC
thanks
i love to wait... wait for better... and better will come...
http://akanoi.webs.com/

sazzadcsedu
Experienced poster
Posts: 136
Joined: Sat Nov 29, 2008 8:01 am
Location: narayangong,bangladesh.
Contact:

WA: 340 Mastermind

Post by sazzadcsedu » 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;

}
Life is more complicated than algorithm.
http://felix-halim.net/uva/hunting.php?id=32359
For Hints: http://salimsazzad.wordpress.com

avinashse
New poster
Posts: 2
Joined: Mon Feb 20, 2012 11:36 am

WA in 340-MasterMind Hints

Post by avinashse » 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.. :oops:

My code :-

Code: Select all

REMOVED AFTER AC.
Thanks for quick reply.. :)
Last edited by avinashse on Tue Feb 28, 2012 11:09 am, edited 1 time in total.

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: WA in 340-MasterMind Hints

Post by brianfry713 » Tue Feb 28, 2012 3:53 am

Try input:
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!

Shahidul.CSE
Experienced poster
Posts: 148
Joined: Sun Jul 13, 2014 4:32 am
Location: Rangpur, Bangladesh

Re: 340 - Master-Mind Hints

Post by Shahidul.CSE » 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.
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

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 340 - Master-Mind Hints

Post by brianfry713 » Tue Dec 02, 2014 9:47 pm

Check input and AC output for thousands of problems on uDebug!

Shahidul.CSE
Experienced poster
Posts: 148
Joined: Sun Jul 13, 2014 4:32 am
Location: Rangpur, Bangladesh

Re: 340 - Master-Mind Hints

Post by Shahidul.CSE » Wed Dec 03, 2014 6:32 am

Thanks ! :D
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

Post Reply

Return to “Volume 3 (300-399)”