## 154 - Recycling

Moderator: Board moderators

dumb dan
Learning poster
Posts: 67
Joined: Tue Aug 05, 2003 1:02 am
You might want to initilize min to something larger than 6.
min=500 should suffice.

Morning
Experienced poster
Posts: 134
Joined: Fri Aug 01, 2003 2:18 pm
Location: Shanghai China
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]
"Learning without thought is useless；thought without learning is dangerous."
"Hold what you really know and tell what you do not know -this will lead to knowledge."-Confucius

dumb dan
Learning poster
Posts: 67
Joined: Tue Aug 05, 2003 1:02 am
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:

Code: Select all

``````3
3``````

Morning
Experienced poster
Posts: 134
Joined: Fri Aug 01, 2003 2:18 pm
Location: Shanghai China
yeah,i got what u mean,they are not in order,now i got AC.Thanks
"Learning without thought is useless；thought without learning is dangerous."
"Hold what you really know and tell what you do not know -this will lead to knowledge."-Confucius

Learning poster
Posts: 73
Joined: Mon Oct 14, 2002 7:15 am
Location: United States
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
#

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.

58050zz
New poster
Posts: 38
Joined: Sat Feb 26, 2005 8:13 am

### How to input

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

dootzky
New poster
Posts: 36
Joined: Tue Apr 12, 2005 12:20 am
Contact:
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

ldaniele
New poster
Posts: 6
Joined: Sat Aug 12, 2006 2:26 am

### 154 Why i get WA??

#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

ldaniele
New poster
Posts: 6
Joined: Sat Aug 12, 2006 2:26 am

### Re: 154 Why i get WA??

I've solved, so you can delete the code!!!

razor_blue
New poster
Posts: 27
Joined: Mon Nov 27, 2006 4:44 am
Location: Indonesia
I don't know why my code is wrong.
Do you know my mistake?

Code: Select all

``````/* removed after AC */
``````
Last edited by razor_blue on Sat Dec 23, 2006 2:49 am, edited 1 time in total.

Jan
Guru
Posts: 1334
Joined: Wed Jun 22, 2005 10:58 pm
Contact:
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:

Code: Select all

``````1
1
1``````
Hope these help.
Ami ekhono shopno dekhi...
HomePage

razor_blue
New poster
Posts: 27
Joined: Mon Nov 27, 2006 4:44 am
Location: Indonesia
Thank you Jan, I added in my program:

Code: Select all

``````if(num_city==1) return 1;
``````
and I got AC.

ata
New poster
Posts: 2
Joined: Wed Nov 07, 2007 5:54 pm

### wa ...anyone help

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

alirezanoori
New poster
Posts: 26
Joined: Fri Jan 02, 2009 12:41 am

### Re: 154 : Recycling

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.

kissu parina
New poster
Posts: 19
Joined: Thu May 20, 2010 8:58 am

### Re: WA 154

thnkx to almost human
one day...