Page 10 of 33
102 - Compile Error
Posted: Wed Apr 23, 2003 2:49 pm
by globi
Hello. I wrote program nr. 102 but I received Compile Error
Could anyone help me?
There's a source code:
[cpp]
#include <stdio.h>
#define B 0 // Brown bottles
#define G 1 // Green bottles
#define C 2 // Clear bottles
int main()
{
char *done;
int pass;
long long bins[3][3],
oldbins,
count,
max;
while(1)
{
pass = 0;
max = 0xffffffffff;
count = 0;
for(int tmp = 0; tmp < 3; tmp++)
for(int tmp2 = 0; tmp2 < 3; tmp2++)
{
oldbins = bins[tmp][tmp2];
scanf("%lld", &bins[tmp][tmp2]);
if(oldbins == bins[tmp][tmp2]) pass++;
}
if(pass == 9) return 0;
count = bins[0][C]+bins[0]+bins[1][G]+bins[1]+bins[2][G]+bins[2][C];
if(count <= max) { max = count; done = "GCB";}
count = bins[0]+bins[0][C]+bins[1][G]+bins[1][C]+bins[2][G]+bins[2];
if(count <= max) { max = count; done = "GBC";}
count = bins[0][G]+bins[0]+bins[1][C]+bins[1]+bins[2][C]+bins[2][G];
if(count <= max) { max = count; done = "CGB";}
count = bins[0]+bins[0][G]+bins[1][C]+bins[1][G]+bins[2][C]+bins[2];
if(count <= max) { max = count; done = "CBG";}
count = bins[0][G]+bins[0][C]+bins[1]+bins[1][C]+bins[2]+bins[2][G];
if(count <= max) { max = count; done = "BGC";}
count = bins[0][C]+bins[0][G]+bins[1][B]+bins[1][G]+bins[2][B]+bins[2][C];
if(count <= max) { max = count; done = "BCG";}
printf("%s %lld\n", done, max);
}
return 0;
}
[/cpp]
Posted: Wed Apr 23, 2003 9:44 pm
by turuthok
Did you submit as C or C++ ... ??? If you're using C, ... "//" will cause an error ...
-turuthok-
My answer of #102 received [WA]
Posted: Thu Apr 24, 2003 11:11 am
by venusaur
[java]import java.io.*;
import java.util.*;
class Main
{
public static String readln(int len)
{
byte lin[]=new byte[len];
int lg=0, car=-1;
try
{
while(lg<len)
{
car=System.in.read();
// if(lg==0&&(car=='\r')||(car=='\n')) continue;
// if((car<0)||(car=='\r')||(car=='\n')) break;
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);
}
static int permute[][]={{0, 2, 1}, {0, 1, 2}, {2, 0, 1}, {2, 1, 0}, {1, 0, 2}, {1, 2, 0}};
static String perstr[]={"BCG", "BGC", "CBG", "CGB", "GBC", "GCB"};
static int compute(int bin[][], int p)
{
int ret=0;
for(int i=0;i<3;i++) for(int j=0;j<3;j++) if(permute[p]
!=j) ret+=bin[j];
return ret;
}
public static void main (String args[])
{
String str;
while((str=readln(80))!=null)
{
StringTokenizer token=new StringTokenizer(str);
String minstr; int minnum;
int bin[][]=new int[3][3];
for(int i=0;i<3;i++) for(int j=0;j<3;j++) bin[j]=Integer.parseInt(token.nextToken());
minstr=perstr[0]; minnum=compute(bin, 0);
for(int i=1;i<6;i++)
{
int t=compute(bin, i);
if(t<minnum) { minstr=perstr; minnum=t; }
}
System.out.println(minstr+" "+minnum);
}
}
}[/java]
I think I have some mistakes but I can't find it
Please help me... 
Posted: Thu Apr 24, 2003 3:48 pm
by globi
I sent it as cpp code, so it should work.
Posted: Thu Apr 24, 2003 7:52 pm
by globi
It's working now. There was an error in line
[cpp]
max = 0xffffffffff;
[/cpp]
There was too small
Thx everyone.
Posted: Thu Apr 24, 2003 7:53 pm
by globi
Ok
I repaired that and I accepted.
Thx.
102 Why WA?
Posted: Fri May 16, 2003 2:28 am
by Zhao Le
Here is my code.
I don't understand why i got WA?
Who can help me i shall be grateful.
[cpp]#include <iostream.h>
struct S
{
int min,cnt;
S *next;
};
struct Glass
{
long Brown,Green,Clear;
};
long Calculate(Glass A,Glass B,Glass C)
{
return A.Green+A.Clear+B.Brown+B.Clear+C.Brown+C.Green;
}
int Convert(int x)
{
switch(x)
{
case 1: return 2;
case 2: return 1;
case 3: return 5;
case 4: return 3;
case 5: return 6;
default: return 4;
}
}
void SS(int i)
{
switch(i)
{
case 1: cout<<"BGC";break;
case 2: cout<<"BCG";break;
case 3: cout<<"GBC";break;
case 4: cout<<"CBG";break;
case 5: cout<<"GCB";break;
case 6: cout<<"CGB";
}
}
void main()
{
long B0,B1,B2,G0,G1,G2,C0,C1,C2;
Glass G[3];
S *p,*q,*head=NULL;
while(cin>>B0>>G0>>C0>>B1>>G1>>C1>>B2>>G2>>C2)
{
G[0].Brown=B0; G[1].Brown=B1; G[2].Brown=B2;
G[0].Green=G0; G[1].Green=G1; G[2].Green=G2;
G[0].Clear=C0; G[1].Clear=C1; G[2].Clear=C2;
int x=0,cnt=7,i,j,k;
long min=65535,t;
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
for(k=0;k<3;k++)
if(i!=j&&i!=k&&j!=k) // cout<<i<<j<<k<<endl;
{
x++;
t=Calculate(G,G[j],G[k]);
if(min>=t)
{
if(min>t)
{
cnt=x;
min=t;
}
else
if(Convert(x)<Convert(cnt))
cnt=x;
}
}
}
p=new S;
if(head==NULL) head=p;
else q->next=p;
p->min=min;
p->cnt=cnt;
p->next=NULL;
q=p;
}
for(p=head;p;p=p->next)
{
SS(p->cnt);
cout<<" "<<p->min<<endl;
}
}[/cpp]
think it easy
Posted: Thu Jun 05, 2003 9:07 pm
by Master
your code is learge but the problem is small
I solve this problem very simple way. there is only 6 type of combination.
check all of them.
use a two dimentional matrix for make it easy.
wish you good luck
think it easy
Posted: Thu Jun 05, 2003 9:10 pm
by Master
your code is learge but the problem is small
I solve this problem very simple way. there is only 6 type of combination.
check all of them.
use a two dimentional matrix for make it easy.
wish you good luck
Posted: Wed Jun 11, 2003 3:28 am
by Zhao Le
Yes, but when the number is same,it should sort,right?
So i still don't know what the problem was?
Can you tell me?
Posted: Wed Jun 11, 2003 12:06 pm
by epsilon0
short analysis of your problem:
1] they wrote:
"The total number of bottles will never exceed 2^31."
2] you wrote:
"long min=65535,t;"
3] conclusion: cannot determine wether you can't read, can't do math, or both.
pardon my roughness, but this kind of error makes me mad. your code is nearly perfect, but it's plagged by a very stupid error.
regards.
thank you
Posted: Wed Jun 11, 2003 1:45 pm
by Zhao Le
I have got it AC.
There are 2 errors.
One you have pointed to me, another is
that i should not use the pointer to save the result.
Thank you, I have often see you helped me and My friends in the Net.
compiler error (102)
Posted: Fri Jun 13, 2003 8:58 pm
by reza ali
Finding compiler error at problem 102.Please findout error

. Here below the code:[c++}]
//@begin_of_source_code
#include<iostream.h>
int main()
{
/*@JUDGE_ID: 32434ZM 102 C++ "Dynamic programming" */
int i,j,bin[3][3],sum[3],min,take;
char *str[6][3],*sequence[3];
while (cin>>bin[0][0]>>bin[0][1]>>bin[0][2]>>bin[1][0]>>bin[1][1]>>bin[1][2]>>bin[2][0]>>bin[2][1]>>bin[2][2])
{
if(bin[1][1]+bin[2][2]<=bin[1][2]+bin[2][1]) {sum[0]=bin[0][1]+bin[0][2]+bin[1][0]+bin[2][0]+bin[1][1]+bin[2][2];*str[0]="BCG";}
else {sum[0]=bin[0][1]+bin[0][2]+bin[1][0]+bin[2][0]+bin[1][2]+bin[2][1];*str[0]="BGC";}
if(bin[0][1]+bin[2][2]<=bin[0][2]+bin[2][1]) {sum[1]=bin[0][0]+bin[2][0]+bin[1][1]+bin[1][2]+bin[0][1]+bin[2][2];*str[1]="CBG";}
else {sum[1]=bin[1][0]+bin[1][2]+bin[0][1]+bin[2][1]+bin[0][2]+bin[2][1];*str[1]="GBC";}
if(bin[0][1]+bin[1][2]<=bin[0][2]+bin[1][1]) {sum[2]=bin[1][0]+bin[0][0]+bin[2][1]+bin[2][2]+bin[0][1]+bin[1][2];*str[2]="CGB";}
else {sum[2]=bin[1][0]+bin[2][1]+bin[2][2]+bin[1][2]+bin[1][1]+bin[0][2];*str[2]="GCB";}
if(sum[0]<=sum[1]){
if(sum[0]<=sum[2]) {min=sum[0];*sequence=*str[0];}
else {min=sum[2];*sequence=*str[2];}
}
else {
if(sum[1]<=sum[2]) {min=sum[1];*sequence=*str[1];}
else {min=sum[2];*sequence=*str[2];}
}
cout<<*sequence<<" "<<min<<endl;}
return 0;
}
//@end_of_source_code[cpp][/cpp]
Looks ok
Posted: Sun Jun 15, 2003 8:14 am
by shamim
ur code compiles using g++(cygwin).
I think the problem is in ur submission.
If u submit using email, some additional things are included,
worse still is, certain mail services transfer ur mail as graphics instead of plain text.
Let me know if this is the problem
Posted: Sun Jun 15, 2003 11:02 pm
by Rav
Could someone tell what is wrong? I think that my compiler isn't good, but when i send it was error. This program is compiling good, but show wrong answer. it isn't entering two last IF-instructiona. I don't know why.
#include<stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
int main()
{
long long int t[10];
long long int max,suma;
int i;
char nap[3];
#ifndef ONLINE_JUDGE
close (0); open ("myprog.in", O_RDONLY);
close (1); open ("myprog.out", O_WRONLY | O_CREAT, 0600);
#endif
t[9]=0;
while ((scanf("%d",&t[0]))==1)
{
for (i=1;i<9;++i)
scanf("%d",&t);
suma=0;
for (i=0;i<9;++i)
suma=suma+t;
max=t[1]+t[5]+t[6];
nap[0]='G';nap[1]='C';nap[2]='B';
if (t[1]+t[3]+t[8]>=max)
{
max=t[1]+t[3]+t[8];
nap[0]='G';nap[1]='B';nap[2]='C';
}
if (t[2]+t[5]+t[6]>=max)
{
max=t[2]+t[5]+t[6];
nap[0]='C';nap[1]='G';nap[2]='B';
}
if (t[2]+t[3]+t[7]>=max)
{
max=t[2]+t[3]+t[7];
nap[0]='C';nap[1]='B';nap[2]='G';
}
if (t[0]+t[4]+t[8]>=max) //this
{
max=t[0]+t[4]+t[8];
nap[0]='B'; nap[1]='G'; nap[2]='C';
}
if (t[0]+t[5]+t[7]>=max) //and this
{
max=t[0]+t[5]+t[7];
nap[0]='B'; nap[1]='C'; nap[2]='G';
}
printf("%c%c%c %d\n",nap[0],nap[1],nap[2],suma-max);
}
}