That is not supported by the C language version judge's gcc takes in. Put thechiunyao wrote:Code: Select all
for(int k=0;k<6;k++)
Code: Select all
int k;
Moderator: Board moderators
That is not supported by the C language version judge's gcc takes in. Put thechiunyao wrote:Code: Select all
for(int k=0;k<6;k++)
Code: Select all
int k;
Code: Select all
#include <stdio.h>
int main(void)
{
long int a[9];
long int b[6];
long int MIN=2147483647;
int MINNUM;
int k;
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(k=0;k<6;k++)
{
if(b[k]<MIN)
{
MIN=b[k];
MINNUM=k;
}
}
if(MINNUM==0)
printf("BCG %ld\n",b[0]);
else if(MINNUM==1)
printf("BGC %ld\n",b[1]);
else if(MINNUM==2)
printf("CBG %ld\n",b[2]);
else if(MINNUM==3)
printf("CGB %ld\n",b[3]);
else if(MINNUM==4)
printf("GBC %ld\n",b[4]);
else if (MINNUM==5)
printf("GCB %ld\n",b[5]);
}
return 0;
}
Code: Select all
#include <stdio.h>
int main(void)
{
long int a[9];
long int b[6];
long int MIN=2147483647;
int MINNUM;
int k;
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)
{
MIN=2147483647;/////////////////////////// Becareful to reset ///////////////
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(k=0;k<6;k++)
{
if(b[k]<MIN)
{
MIN=b[k];
MINNUM=k;
}
}
if(MINNUM==0)
printf("BCG %ld\n",b[0]);
else if(MINNUM==1)
printf("BGC %ld\n",b[1]);
else if(MINNUM==2)
printf("CBG %ld\n",b[2]);
else if(MINNUM==3)
printf("CGB %ld\n",b[3]);
else if(MINNUM==4)
printf("GBC %ld\n",b[4]);
else if (MINNUM==5)
printf("GCB %ld\n",b[5]);
}
return 0;
}
Code: Select all
#include <iostream>
#include <string>
using namespace std;
int take( int n, string* str, int* b, int sum )
{
switch( n )
{
case 1:
*str = "BGC";
return sum - b[ 0 ] - b[ 4 ] - b[ 8 ];
break;
case 2:
*str = "BCG";
return sum - b[ 0 ] - b[ 5 ] - b[ 7 ];
break;
case 3:
*str = "GBC";
return sum - b[ 1 ] - b[ 3 ] - b[ 8 ];
break;
case 4:
*str = "GCB";
return sum - b[ 1 ] - b[ 5 ] - b[ 5 ];
break;
case 5:
*str = "CBG";
return sum - b[ 2 ] - b[ 3 ] - b[ 7 ];
break;
case 6:
*str = "CGB";
return sum - b[ 2 ] - b[ 4 ] - b[ 6 ];
break;
}
}
int main()
{
int b[ 9 ];
while( cin >> b[0] >> b[1] >> b[2] >> b[3] >> b[4] >> b[5] >> b[6] >> b[7] >> b[8] )
{
int move = b[0] + b[1] + b[2] + b[3] + b[4] + b[5] + b[6] + b[7] + b[8];
int small = -1;
string str;
for( int i = 1; i <= 6; ++i )
{
int s;
string s2;
s = take( i, &s2, b, move );
if( s < small || small == -1 )
{
small = s;
str = s2;
}
else if( s == small && s2 < str )
{
str = s2;
}
}
cout << str << " " << small << endl;
}
return 0;
}
so according to this.... the process goes:jan-jun-john wrote:I can get AC!!!This is the cause of WA.Code: Select all
while (true) { if (cin.eof()) break; . . .
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) {...
Code: Select all
for(i=0; i<N; i++)
{ if(allcomb[i]<min)
{
strcpy(glass,col[i]);
min=allcomb[i];
}
else if(allcomb[i]==min)
{
if( strcmp(glass,col[i])==1)
strcpy(glass,col[i]);
}
}
printf("%s %ld\n",glass,min);