154 - Recycling
Moderator: Board moderators
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]
[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
"Hold what you really know and tell what you do not know -this will lead to knowledge."-Confucius
input:
output:
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
#
Code: Select all
3
3
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"
"#";
i can run my code
..
how to input like the (initialize) format
without garbage data (ex:space)
when i encounter space.will bug
-
- New poster
- Posts: 36
- Joined: Tue Apr 12, 2005 12:20 am
- Location: belgrade, serbia (ex yugoslavia)
- 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
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??
#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
#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??
I've solved, so you can delete the code!!!
-
- 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?
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.
If there is only one city its clear that it should be the winner. Check the samples...
Input:
Output:
Hope these help.
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
#
Code: Select all
1
1
1
Ami ekhono shopno dekhi...
HomePage
HomePage
-
- New poster
- Posts: 27
- Joined: Mon Nov 27, 2006 4:44 am
- Location: Indonesia
Thank you Jan, I added in my program:
and I got AC. 
Code: Select all
if(num_city==1) return 1;

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...
thanx in advance for any help
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;
}
-
- 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.
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.
-
- New poster
- Posts: 19
- Joined: Thu May 20, 2010 8:58 am