Page 23 of 33

Posted: Thu Jan 05, 2006 7:49 am
by =viki=
damn... thats silly


thanx anyway for pointing out my error..
but how is it getting compile error though..
its doing fine on my system(using DEV C++)

Posted: Thu Jan 05, 2006 11:29 am
by Mohammad Mahmudur Rahman
In order to be compilled under judge your program must exclude all non-ANSI standard features. So, you can't use all your DEV-C++ compiler features & be assured that it'll be alright in the judge. You may consult your compiler's documentation for information about which features are ANSI standard & which are not.

to chunyi81:
Are you sure that a difference in %d & %ld will result in CE in UVa judge? :o I really doubt that. I think =viki= received CE in this program for using C++ style comment & submitting as C program. If this program is submitted as a C++ program, I don't think it'll get CE.

Posted: Thu Jan 05, 2006 12:01 pm
by =viki=
C++ style comment was the prob...

thanx for the help... i got AC after remo ving those comments...

Posted: Thu Jan 05, 2006 12:13 pm
by =viki=
got AC.... C++ style comment was the prob

after removing the comment i got AC....

Posted: Thu Jan 05, 2006 1:08 pm
by chunyi81
Thanks to Mohammad Mahmudur Rahman for pointing out the actual problem. I was able to compile viki's code in a Unix environment using gcc 2.95.3 though, without any problems. And I realized why my code for problem 142 was getting CE from the judge when I submitted it as C code. I was also using C++ style comments myself in C code. :oops:

Is the OJ using an older version of the gcc 2.95 compiler?

102 - WA

Posted: Wed Jan 11, 2006 10:38 pm
by totobogy
Hi! I'm new to ACM and this forum. plz help me with this. runs fine for sample input but gives WA on judge
aren't there only these six possibilities? can someone provide some test cases

Code: Select all

#include<stdio.h>

int main()
{
	unsigned long bins[9]; /*2d array[3][3] could hv been used too*/
	unsigned long cost[6];/*cost of BCG BGC CBG CGB GBC GCB (in that order) - only these six r possible*/
	unsigned long sum;
	
	int i;
	int c;
	while((c=getc(stdin)) != EOF)
	{
		ungetc(c,stdin);
		
		sum = 0; /*reset*/
		
  		/*BGC BGC BGC = 012 345 678*/
		for(i=0;i<9;i++)
		{
			scanf("%lu",&bins[i]);
			sum += bins[i];
		}
	
 		/*Now calculating costs*/
 		/*BCG*/
 		cost[0] = sum - (bins[0]+ bins[5]+ bins[7]);
 		/*BGC*/
 		cost[1] = sum - (bins[0]+ bins[4]+ bins[8]);
 		/*CBG*/
 		cost[2] = sum - (bins[2]+ bins[3]+ bins[7]);
 		/*CGB*/
 		cost[3] = sum - (bins[2]+ bins[4]+ bins[6]);
 		/*GBC*/
 		cost[4] = sum - (bins[1]+ bins[3]+ bins[8]);
 		/*GCB*/
 		cost[5] = sum - (bins[1]+ bins[5]+ bins[6]);
	
        /*find smallest cost packing scheme*/
	
         int min = 0;
         for(i=1;i<6;i++)
         	if(cost[i] < cost[min])
         		min = i;
			
	    /*print output*/
	    switch(min)
	    {
	    	case 0: printf("BCG %lu\n",cost[min]);break;
	    	case 1: printf("BGC %lu\n",cost[min]);break;
	    	case 2: printf("CBG %lu\n",cost[min]);break;
	    	case 3: printf("CGB %lu\n",cost[min]);break;
	    	case 4: printf("GBC %lu\n",cost[min]);break;
	    	case 5: printf("GCB %lu\n",cost[min]);break;
    	}
	}
	return 0;
}



Posted: Thu Jan 12, 2006 11:49 am
by Mohammad Mahmudur Rahman
Try taking the input in this way -

Code: Select all

while(scanf(" %lu",&bins[0])==1)
{ 
      sum = bins[0]; /*reset*/ 
       
        /*BGC BGC BGC = 012 345 678*/ 
      for(i=1;i<9;i++) 
      { 
         scanf("%lu",&bins[i]); 
         sum += bins[i]; 
      }
    
      .....
}
Everything else should be OK.

Thanks. It worked

Posted: Thu Jan 12, 2006 1:55 pm
by totobogy
Thanks a lot. This was the problem indeed. But could you tell me why didn't the earlier code work?

Posted: Thu Jan 12, 2006 2:18 pm
by Mohammad Mahmudur Rahman
As far as my experience goes, ungetc() method at times (not always) fails in the UVa judge. The reason is most probably, there may be some spaces after an input line. For example, test your program for the following input

Code: Select all

1_2_3_4_5_6_7_8_9
1_2_3_4_5_6_7_8_9_
/* Here each underscore represents a single space char. */
if you use getc() & ungetc(), I think you'll get

Code: Select all

BCG 30
BCG 30
BCG 30

Thanks again

Posted: Thu Jan 12, 2006 8:16 pm
by totobogy
I see. Thanks for the valuable clarification and your time!

102 please help!

Posted: Tue Feb 07, 2006 6:36 pm
by jan-jun-john
I can't get "Accepted", but I don't know what is wrong with my program.
Please, help!

Code: Select all

Sorry, it was removed.

Posted: Wed Feb 08, 2006 2:31 am
by jan-jun-john
I noticed these sentences not filled well.
If more than one order of brown, green, and clear bins yields the minimum number of movements then the alphabetically first string representing a minimal configuration should be printed.
So, I improved my code, but still WA...
Where is Wrong ?

Code: Select all

Sorry, it was removed.

Problem is solved!

Posted: Wed Feb 08, 2006 3:09 am
by jan-jun-john
I can get AC!!!

Code: Select all

while (true) {
if (cin.eof()) break;
.
.
.
This is the cause of WA.
This should be changed,

Code: Select all

while (scanf("%d %d %d %d %d %d %d %d %d", 
			&data[0],&data[1],&data[2], 
			&data[3],&data[4],&data[5], 
			&data[6],&data[7],&data[8])==9) {...
I hope my effort will help following person!

102 help me always "Compile error"

Posted: Mon Feb 13, 2006 11:12 am
by chiunyao
I always get Compile error ,but i don't know why??

please help me ,i'm new to ACM ><



thanks

Code: Select all

#include <stdio.h> 
int main(void) 
{ 
	 long int a[9]; 
	 long int b[6]; 
	 long int MIN=2147483647;
	 int MINNUM; 


	while(scanf("%ld%ld%ld%ld%ld%ld%ld%ld%ld", &a[0], &a[1], &a[2], &a[3], &a[4], &a[5], &a[6], &a[7], &a[8]) == 9) 
	{ 
		


	b[1]=a[3]+a[6]+a[1]+a[7]+a[2]+a[5]; 
	b[0]=a[3]+a[6]+a[2]+a[8]+a[1]+a[4]; 
	b[4]=a[4]+a[7]+a[0]+a[6]+a[2]+a[5]; 
	b[5]=a[4]+a[7]+a[2]+a[8]+a[0]+a[3]; 
	b[2]=a[5]+a[8]+a[0]+a[6]+a[1]+a[4]; 
	b[3]=a[5]+a[8]+a[1]+a[7]+a[0]+a[3]; 


	for(int k=0;k<6;k++) 
	{ 

		if(b[k]<MIN) 
		{ 
			MIN=b[k]; 
			MINNUM=k; 
		} 
	} 
		if(MINNUM==0) 
		printf("BCG %lu\n",b[0]);
	else if(MINNUM==1)
		printf("BGC %lu\n",b[1]);
	else if(MINNUM==2) 
		printf("CBG %lu\n",b[2]);
	else if(MINNUM==3)
		printf("CGB %lu\n",b[3]);
	else if(MINNUM==4)
		printf("GBC %lu\n",b[4]);
	else if (MINNUM==5)
		printf("GCB %lu\n",b[5]);
	 	} 
return 0; 
} 

Posted: Tue Feb 14, 2006 7:46 am
by shamim
I submitted your code as C++ and it did not get compile error.
But it got compile error using the C option.
Perhaps this is the problem. :wink: