Page 2 of 2
Posted: Tue Oct 05, 2004 10:32 am
by dumb dan
You might want to initilize min to something larger than 6.
min=500 should suffice.
Posted: Tue Oct 05, 2004 10:36 am
by Morning
yeah,that's a mistake.but after changed it to 600,i still keep getting WA
[cpp]
#include <iostream>
#include <cstring>
using namespace std;
int calculate(char data[101][5][4],int n)
{
int min = 600,sum,record;
for(int i = 0;i < n;i++)
{
sum = 0;
for(int j = 0;j < n;j++)
{
if(j == i) continue;
for(int k = 0;k < 5;k++)
{
if(strcmp(data[k],data[j][k]) != 0)
{
sum++;
}
}
}
if(sum < min)
{
min = sum;
record = i;
}
}
return record + 1;
}
int main()
{
int i,n = 0;
char string[20];
char data[101][5][4];
char seps[] = ",";
char *token;
while(cin >> string)
{
if(string[0] == 'e')
{
cout << calculate(data,n) << endl;
n = 0;
continue;
}
if(string[0] == '#') {break;}
token = strtok( string, seps );
i = 0;
while( token != NULL )
{
strcpy(data[n][i++],token);
token = strtok( NULL, seps );
}
n++;
}
return 0;
}[/cpp]
Posted: Tue Oct 05, 2004 11:22 am
by dumb dan
input:
Code: Select all
g/N,y/G,o/S,r/A,b/P
y/N,b/S,r/G,g/A,o/P
r/N,y/G,o/S,b/P,g/A
e
r/A,y/G,o/S,b/P,g/N
r/G,y/N,o/P,b/S,g/A
r/N,y/G,o/S,b/P,g/A
e
#
output:
Posted: Tue Oct 05, 2004 11:31 am
by Morning
yeah,i got what u mean,they are not in order,now i got AC.Thanks
Posted: Sat Feb 26, 2005 10:49 am
by rjhadley
Almost Human wrote:Try the following input:
r/G,o/P,y/S,g/A,b/N
r/P,o/S,y/G,g/A,b/N
r/G,o/P,y/S,g/A,b/N
e
#
your program produces :
3
the correct one should produces :
1
Your input here is ambiguous. However,
Problem Specification wrote:Note that there will always be a clear winner.
How to input
Posted: Sun Feb 27, 2005 12:44 pm
by 58050zz
Code: Select all
string s=
"r/P,o/G,y/S,g/A,b/N"
"r/G,o/S,y/A,g/P,b/N"
"r/G,o/S,y/A,g/P,b/N"
"e"
"#";
if i initialize the string
i can run my code
..
how to input like the (initialize) format
without garbage data (ex:space)
when i encounter space.will bug
Posted: Tue May 31, 2005 12:42 am
by dootzky
damn ppl, this problem was really really badly described.
if it waren't for "almost human" dude, i would've never get ACC.
someone should do a better job when describing problems, like in volumes 600,700,etc.
first couple of volumes has terrible, terrible descriptions.
thx for the help, "almost human" mon!
ReSpeCT,
dootzky
154 Why i get WA??
Posted: Mon Aug 21, 2006 9:55 pm
by ldaniele
#include<iostream>
#include<string>
#define PROVA
#ifdef PROVA
#include<fstream>
using std::ofstream;
using std::ifstream;
using std::string;
//using std::cout;
ofstream cout("output.txt");
ifstream cin("input.txt");
#endif
#ifndef PROVA
using std::cin;
using std::cout;
using std::string;
#endif
//variabili globali
const short int rows=500, cols=5;
//matrice citt
Re: 154 Why i get WA??
Posted: Tue Aug 22, 2006 5:26 pm
by ldaniele
I've solved, so you can delete the code!!!
Posted: Sat Dec 16, 2006 7:28 am
by razor_blue
I don't know why my code is wrong.
Do you know my mistake?
Posted: Sat Dec 16, 2006 11:51 am
by Jan
If there is only one city its clear that it should be the winner. Check the samples...
Input:
Code: Select all
g/A,b/N,y/S,o/G,r/P
e
r/P,b/N,o/G,g/A,y/S
e
b/N,y/S,g/A,r/P,o/G
e
#
Output:
Hope these help.
Posted: Sat Dec 23, 2006 2:48 am
by razor_blue
Thank you Jan, I added in my program:
and I got AC.

wa ...anyone help
Posted: Mon Jan 07, 2008 7:49 pm
by ata
i have tested the test inputs in the forum....
can anyone plz tell me why my program gives wa...
here is my code...
Code: Select all
#include<stdio.h>
#include<string.h>
char recycle[6]="PGASN";
char waste[6]="roygb";
int city[100][5];
int result[100];
int find_max(int x[],int num)
{
int max,i,index;
max=0;
for(i=0;i<num;i++)
if(result[i]>max)
{
max=result[i];
index=i;
}
return index;
}
int main()
{
char temp[30];
int cit,x,i,j,k,num,n;
char c,cc;
cit=0;
while(scanf("%s",&temp)==1)
{
if(strcmp(temp,"#")==0)
break;
if(temp[0]=='e')
{
if(cit==1)
{
printf("1\n");
continue;
}
num=cit;
cit=0;
i=0;
n=0;
for(i=0;i<num;i++)
result[i]=0;
n=0;
while(n<num)
{
for(i=0;i<num;i++)
{
if(n==i)
continue;
for(j=0;j<5;j++)
{
if(city[n][j]==city[i][j])
result[n]++;
}
}
n++;
}
printf("%d\n",find_max(result,num)+1);
continue;
}
for(k=0;k<strlen(temp);k=k+4)
{
c=temp[k];
cc=temp[k+2];
j=0;
while(c!=waste[j])
j++;
x=0;
while(cc!=recycle[x])
x++;
city[cit][j]=x;
}
cit++;
}
return 0;
}
thanx in advance for any help
Re: 154 : Recycling
Posted: Thu Feb 26, 2009 12:52 pm
by alirezanoori
I am getting WA too, and my algorithm is pretty much the same as yours. I debugged my program and it works as expected but I don't know why I am getting WA! I think there is some critical inputs because I am sure this is the right algorithm.
If anyone has some critical inputs please post it.
If you need my code I am ready to post it here. Just tell me.
Thanks.
Re: WA 154
Posted: Fri Feb 11, 2011 7:31 am
by kissu parina
thnkx to almost human