Page 22 of 33

102 Compile Error, but no error when using VC/GCC/BCC .

Posted: Thu Aug 04, 2005 5:30 am
by kobe
I tried many ways, but still receive compile error
plz help, thx~

Code: Select all

#include <cstdio>
#include <iostream>
#include <string>
#define BROWN 0
#define GREEN 1
#define CLEAR 2
#ifndef INT_MAX
	#define INT_MAX 0xFFFFFFFFF
#endif

// UserID : 3931RL

using namespace std;

class Problem102{
	
	private:	
	
		class RecycleBin{
			public:
				int glass[3];
				int hold;
				
				RecycleBin(){
					set(0,0,0);
				}
								
				void set(int b, int g, int c){
					glass[BROWN]=b; glass[GREEN]=g; glass[CLEAR]=c;
				}
				
		};
		void parseInput();
		RecycleBin *bin;
		
	public:
				
		void solve(){
			
			parseInput();
			
		}
		
		~Problem102(){
			delete [] bin;
		}
		
};

void Problem102::parseInput(){
	
			int order[6][3]={ {BROWN, CLEAR, GREEN},
												{BROWN, GREEN, CLEAR},
												{CLEAR, BROWN, GREEN},
												{CLEAR, GREEN, BROWN},
												{GREEN, BROWN, CLEAR},
												{GREEN, CLEAR, BROWN} };
			
			char orderName[3]={'B', 'G', 'C'};
			int minOrder;
			bin=new RecycleBin[3];
			int minResult;
			int count,i,j,k;
			
			int bin0b,bin0g,bin0c,bin1b,bin1g,bin1c,bin2b,bin2g,bin2c;
			while( scanf("%d %d %d %d %d %d %d %d %d", &bin0b, &bin0g, &bin0c, &bin1b, &bin1g, &bin1c, &bin2b, &bin2g, &bin2c )==9 ){
							
					// set glasses to bins
					bin[0].set(bin0b,bin0g,bin0c);
					bin[1].set(bin1b,bin1g,bin1c);
					bin[2].set(bin2b,bin2g,bin2c);
					
					minResult=INT_MAX;
					minOrder = -1;
					for( i=0 ; i<6 ; i++ ){
						
						bin[0].hold=order[i][0];
						bin[1].hold=order[i][1];
						bin[2].hold=order[i][2];
						
						count = 0;
						for( j=0 ; j < 3 ; j++ ){
							for( k=0 ; k < 3 ; k++ ){
								if( k != bin[j].hold ){
									count += bin[j].glass[k];
								}
							}
						}
						if( count < minResult ){
							minResult=count;
							minOrder=i;
						}
						
					}
					
					printf("%c%c%c %d\n", orderName[order[minOrder][0]], orderName[order[minOrder][1]], orderName[order[minOrder][2]], minResult);
								
			}
	
}

int main(){

	Problem102 clsP102=Problem102();
	clsP102.solve();
	
	return 0;
	
}

[/quote]

Posted: Thu Aug 04, 2005 7:41 am
by kobe
Sorry I found the problem finally

dut to
#define INT_MAX 0xFFFFFFFF

int minResult;
minResult=INT_MAX;

signed integer MAX=2147483647
the definition will cause conversion error :(

why WA

Posted: Wed Aug 24, 2005 8:07 am
by abyss
pls help me with this

Code: Select all

#include<stdio.h>



int bin[3][3],total[6]={0};
char color[4]="BGC";

void seq(char str[4],int index)
{
    int i,j;
    for(i=0;i<3;i++)
    {
	for(j=0;j<3;j++)
	{
	    if(color[j]!=str[i])
	      total[index]+=bin[i][j];
     }
}

}

int main()
{
    int i,j,index,min=0;

    char str[6][4]={"BCG","BGC","CBG","CGB","GBC","GCB"};
    for(i=0;i<3;i++)
    {
      for(j=0;j<3;j++)
      {
    	scanf("%d",&bin[i][j]);
     	
    }
}
    
    for(i=0;i<6;i++)
     seq(str[i],i);
     min=total[0];index=0;
    for(i=1;i<6;i++)
    {
	if(total[i]<min)
	{
	  min=total[i];
	  index=i;
     }
    }

    printf("%s %d\n",str[index],total[index]);
    
   
    return 0;
}       
its gives WA when submitted.

102 compile error

Posted: Thu Sep 01, 2005 2:25 pm
by michaelfung

Code: Select all

program p102;

procedure try (level:shortint);
var
   i:shortint;
begin

.. 

end;

begin
   while (not (eof)) do
   begin

     ..
      try (1);

      ..

   end;
end.
I can compile it using freepascal yet cannot complie it on the judge .
Can anyone help me ??
Thx a lot.

Posted: Thu Sep 01, 2005 2:42 pm
by Observer
Hi,

I think you should change your procedure name. The name "try" is not allowed.

Please remove your code after you get Accepted :-)

Posted: Thu Sep 01, 2005 4:53 pm
by michaelfung
thx a lot .
i got accepted. :)
Sorry for posting the whole program.

102 judge only know the word "wrong answer"

Posted: Sun Sep 04, 2005 12:42 pm
by Tanu
Hi,
would u like to see my code...
I have submitted it so many limes but failed...
Plz help...

Code: Select all

#include<stdio.h>
#include<string.h>

main()
{
	long aG,aB,aC,bG,bB,bC,cG,cB,cC,min,temp;
	char s[10];

	
while(scanf("%ld%ld%ld%ld%ld%ld%ld%ld%ld",&aB,&aG,&aC,&bB,&bG,&bC,&cB,&cG,&cC)==9)
	{
		min=    aC+aG
			+bB   +bG
			+cB+cC   ;
		strcpy(s,"BCG");

		temp=   +aC+aG
			+bB+bC   
			+cB   +cG;
		if(temp<=min)
		{
			min=temp;
			strcpy(s,"BGC");
		}
		
		temp= aB   +aG
			   +bC+bG
			+cB+cC   ;
		if(temp<=min)
		{
			min=temp;
			strcpy(s,"CBG");
		}
		
		temp= aB   +aG
			+bB+bC   
			   +cC+cG;
		if(temp<=min)
		{
			min=temp;
			strcpy(s,"CGB");
		}
		
		temp= aB+aC   
			   +bC+bG
			+cB   +cG;
		if(temp<=min)
		{
			min=temp;
			strcpy(s,"GBC");
		}
		
		temp= aB+aC   
			+bB   +bG
			   +cC+cG;
		if(temp<=min)
		{
			min=temp;
			strcpy(s,"GCB");
		}
		printf("%s %ld\n",s,min);
	}
}[/quote]

Posted: Mon Sep 05, 2005 8:09 pm
by Jan
I think your code is ok. Just some special test cases. When BCG, CBG, BGC ... all are equal you should print them alphabetically. Your checking is corect. But

Code: Select all

if(temp<min)  // not if(temp<=min)
      { 
         min=temp; 
         strcpy(s,"BGC"); 
      } 
You should change all of them.

Hope it works. :)

help, 102

Posted: Wed Dec 07, 2005 3:19 pm
by Dewr
server said me "WRONG ANSWER" :cry:

[/code]
#include <stdio.h>

#define BROWN 0
#define GREEN 1
#define CLEAN 2

#define FIRST 0
#define SECOND 1
#define THIRD 2

#define GBC "GBC"
#define GCB "GCB"
#define BCG "BCG"
#define BGC "BGC"
#define CBG "CBG"
#define CGB "CGB"

int i, j; // i and j.
int in[3][3]; //the number of bottles. ex>in[BROWN][FIRST]
int n[3][3]; //the number of bottle movements.(one color's) ex>n[GREEN][FIRST]
int sum[3]; //sum of number of bottles-same color all.
char* max;

void estimate();
void choose();

int main()
{
lalala:
#ifndef ONLINE_JUDGE
_flushall();
#endif
if(scanf("%d %d %d %d %d %d %d %d %d", &in[BROWN][FIRST], &in[GREEN][FIRST], &in[CLEAN][FIRST], &in[BROWN][SECOND], &in[GREEN][SECOND], &in[CLEAN][SECOND], &in[BROWN][THIRD], &in[GREEN][THIRD], &in[CLEAN][THIRD]) == EOF)
{
#ifndef ONLINE_JUDGE
printf("exit...");
#endif
return 0;
}

estimate();

choose();

printf("%s %d\n", max, i);

goto lalala;
}

void estimate()
{
for(i=0; i<3; i++)
sum = in[FIRST] + in[SECOND] + in[THIRD];

for(i=0; i<3; i++)
{
for(j=0; j<3; j++)
{
n[j] = sum - in[j];
}
}
}

void choose()
{
i = n[GREEN][FIRST] + n[BROWN][SECOND] + n[CLEAN][THIRD];
max = GBC;

j = n[GREEN][FIRST] + n[CLEAN][SECOND] + n[BROWN][THIRD];
if(j <= i)
{
i = j;
max = GCB;
}

j = n[CLEAN][FIRST] + n[GREEN][SECOND] + n[BROWN][THIRD];
if(j <= i)
{
i = j;
max = CGB;
}

j = n[CLEAN][FIRST] + n[BROWN][SECOND] + n[GREEN][THIRD];
if(j <= i)
{
i = j;
max = CBG;
}

j = n[BROWN][FIRST] + n[GREEN][SECOND] + n[CLEAN][THIRD];
if(j <= i)
{
i = j;
max = BGC;
}

j = n[BROWN][FIRST] + n[CLEAN][SECOND] + n[GREEN][THIRD];
if(j <= i)
{
i = j;
max = BCG;
}
}

Posted: Fri Dec 09, 2005 7:50 am
by Rocky
some test case for you...

Code: Select all

1 2 3 4 5 6 7 8 9
1000 200 1500 350 5000 1000 1000 2000 13000
5 10 5 20 10 5 10 20 10
60 20 1000 1000 60 20 10000 20 500
20 1000 50 2000 50 500 1500 20 3000
20 1000 50 2000 50 5000 1500 20 300
GOOD LUCK
Rocky

Posted: Fri Dec 09, 2005 8:55 am
by Timo
here is the output from rocky test case

Code: Select all

BCG 30
BGC 6050
CBG 50
CGB 1620
GBC 2140
GCB 2440
I hope you can get AC :D

Posted: Sun Dec 11, 2005 3:10 pm
by gladiatorcn
my program passes all your cases but is still getting a WA. so sad :~

// 102
// Guo Fei
#include <iostream>

using namespace std;

int main()
{
char table[3] = {'B', 'C', 'G'};
int min;
int bin[3][3];
char solution[3];

while(cin>>bin[0][0]>>bin[0][2]>>bin[0][1]>>bin[1][0]>>bin[1][2]>>bin[1][1]
>>bin[2][0]>>bin[2][2]>>bin[2][1])
{
min = 0xffff;
for(int i = 0; i < 3; i++ )
for(int j = 0; j < 3; j++ )
{
if( j != i )
{
for( int k = 0; k < 3; k++ )
{
int s = 0;
for( int p = 0; p < 3; p++ )
for( int q = 0; q < 3; q++ )
s += bin[p][q];
if( k != i && k != j && s - bin[0] - bin[1][j] - bin[2][k] < min )
{
min = s - bin[0] - bin[1][j] - bin[2][k];
solution[0] = table;
solution[1] = table[j];
solution[2] = table[k];
}
}
}
}
cout<<solution[0]<<solution[1]<<solution[2]<<" "<<min<<endl;
}
return 1;
}

Posted: Thu Jan 05, 2006 6:30 am
by =viki=
plz help getting compile erroe (no error on my system though)
im using dev c++...

Code: Select all

#include<stdio.h>

void _cpy(char *des, char *src)
{
	int i=0;
	while(src[i]!='\0')
	{
		des[i]=src[i];
		i++;
	}
	des[i]='\0';
}

int main(void)
{
	long int arr[9],min=0;
	int i;
	char str[5];
	while(scanf("%ld%ld%ld%ld%ld%ld%ld%ld%ld",&arr[0],&arr[1],&arr[2],&arr[3],&arr[4],&arr[5],&arr[6],&arr[7],&arr[8])==9)
	{
		//bcg
		min=arr[1]+arr[2]+arr[3]+arr[4]+arr[6]+arr[8];
		_cpy(str,"BCG");
		//bgc
		if(min>(arr[1]+arr[2]+arr[3]+arr[5]+arr[6]+arr[7]))
		{
			min=arr[1]+arr[2]+arr[3]+arr[5]+arr[6]+arr[7];
			_cpy(str,"BGC");
		}
		//cbg
		if(min>(arr[0]+arr[1]+arr[4]+arr[5]+arr[6]+arr[8]))
		{
			min=arr[0]+arr[1]+arr[4]+arr[5]+arr[6]+arr[8];
			_cpy(str,"CBG");
		}
		//cgb
		if(min>(arr[0]+arr[1]+arr[3]+arr[5]+arr[7]+arr[8]))
		{
			min=arr[0]+arr[1]+arr[3]+arr[5]+arr[7]+arr[8];
			_cpy(str,"CGB");
		}
		//gbc
		if(min>(arr[0]+arr[2]+arr[4]+arr[5]+arr[6]+arr[7]))
		{
			min=arr[0]+arr[2]+arr[4]+arr[5]+arr[6]+arr[7];
			_cpy(str,"GBC");
		}
		//gcb
		if(min>(arr[0]+arr[2]+arr[3]+arr[4]+arr[7]+arr[8]))
		{
			min=arr[0]+arr[2]+arr[3]+arr[4]+arr[7]+arr[8];
			_cpy(str,"GCB");
		}
		printf("%s %d\n",str,min);
	}
	return 0;
}
plz help ... and if this prog compiles will it get AC (im getting correct output on my system)DEV C++

102 compile error (compiled on my system)usin DEV C++

Posted: Thu Jan 05, 2006 6:35 am
by =viki=
here is the code getting CE

Code: Select all

#include<stdio.h> 

void _cpy(char *des, char *src) 
{ 
   int i=0; 
   while(src[i]!='\0') 
   { 
      des[i]=src[i]; 
      i++; 
   } 
   des[i]='\0'; 
} 

int main(void) 
{ 
   long int arr[9],min=0; 
   int i; 
   char str[5]; 
   while(scanf("%ld%ld%ld%ld%ld%ld%ld%ld%ld",&arr[0],&arr[1],&arr[2],&arr[3],&arr[4],&arr[5],&arr[6],&arr[7],&arr[8])==9) 
   { 
      //bcg 
      min=arr[1]+arr[2]+arr[3]+arr[4]+arr[6]+arr[8]; 
      _cpy(str,"BCG"); 
      //bgc 
      if(min>(arr[1]+arr[2]+arr[3]+arr[5]+arr[6]+arr[7])) 
      { 
         min=arr[1]+arr[2]+arr[3]+arr[5]+arr[6]+arr[7]; 
         _cpy(str,"BGC"); 
      } 
      //cbg 
      if(min>(arr[0]+arr[1]+arr[4]+arr[5]+arr[6]+arr[8])) 
      { 
         min=arr[0]+arr[1]+arr[4]+arr[5]+arr[6]+arr[8]; 
         _cpy(str,"CBG"); 
      } 
      //cgb 
      if(min>(arr[0]+arr[1]+arr[3]+arr[5]+arr[7]+arr[8])) 
      { 
         min=arr[0]+arr[1]+arr[3]+arr[5]+arr[7]+arr[8]; 
         _cpy(str,"CGB"); 
      } 
      //gbc 
      if(min>(arr[0]+arr[2]+arr[4]+arr[5]+arr[6]+arr[7])) 
      { 
         min=arr[0]+arr[2]+arr[4]+arr[5]+arr[6]+arr[7]; 
         _cpy(str,"GBC"); 
      } 
      //gcb 
      if(min>(arr[0]+arr[2]+arr[3]+arr[4]+arr[7]+arr[8])) 
      { 
         min=arr[0]+arr[2]+arr[3]+arr[4]+arr[7]+arr[8]; 
         _cpy(str,"GCB"); 
      } 
      printf("%s %d\n",str,min); 
   } 
   return 0; 
} 
plz help .... and if its compiled will it get AC i ve got only 2 cases to test..

Posted: Thu Jan 05, 2006 6:46 am
by chunyi81
Check this line:

Code: Select all

printf("%s %d\n",str,min);
min is a long int, but you are using %d conversion specifier. It should be %ld.

Search the forum. There should be some test cases lying around somewhere.