why this shows runtime error, this is uva 102
Posted: Thu Dec 23, 2010 7:25 pm
import java.util.Scanner;
class ebp
{
public static int main(String[] args)
{
Scanner s = new Scanner(System.in);
int nb[]=new int[9];
int m=2147483647;
int t=0;
String str="abc";
while(s.hasNextInt())
{
nb[0]=s.nextInt();
nb[1]=s.nextInt();
nb[2]=s.nextInt();
nb[3]=s.nextInt();
nb[4]=s.nextInt();
nb[5]=s.nextInt();
nb[6]=s.nextInt();
nb[7]=s.nextInt();
nb[8]=s.nextInt();
m=2147483647;
t=0;
t=nb[1]+nb[2]+nb[3]+nb[4]+nb[6]+nb[8];
if(t<m)
{
m=t;
str="BCG";
}
t=nb[1]+nb[2]+nb[3]+nb[5]+nb[6]+nb[7];
if(t<m)
{
m=t;
str="BGC";
}
t=nb[1]+nb[0]+nb[5]+nb[4]+nb[6]+nb[8];
if(t<m)
{
m=t;
str="CBG";
}
t=nb[1]+nb[0]+nb[3]+nb[5]+nb[7]+nb[8];
if(t<m)
{
m=t;
str="CGB";
}
t=nb[0]+nb[2]+nb[5]+nb[4]+nb[6]+nb[7];
if(t<m)
{
m=t;
str="GBC";
}
t=nb[0]+nb[2]+nb[3]+nb[4]+nb[7]+nb[8];
if(t<m)
{
m=t;
str="GCB";
}
if(str!=null)System.out.println(str+" "+m);
}
return 0;
}
}
class ebp
{
public static int main(String[] args)
{
Scanner s = new Scanner(System.in);
int nb[]=new int[9];
int m=2147483647;
int t=0;
String str="abc";
while(s.hasNextInt())
{
nb[0]=s.nextInt();
nb[1]=s.nextInt();
nb[2]=s.nextInt();
nb[3]=s.nextInt();
nb[4]=s.nextInt();
nb[5]=s.nextInt();
nb[6]=s.nextInt();
nb[7]=s.nextInt();
nb[8]=s.nextInt();
m=2147483647;
t=0;
t=nb[1]+nb[2]+nb[3]+nb[4]+nb[6]+nb[8];
if(t<m)
{
m=t;
str="BCG";
}
t=nb[1]+nb[2]+nb[3]+nb[5]+nb[6]+nb[7];
if(t<m)
{
m=t;
str="BGC";
}
t=nb[1]+nb[0]+nb[5]+nb[4]+nb[6]+nb[8];
if(t<m)
{
m=t;
str="CBG";
}
t=nb[1]+nb[0]+nb[3]+nb[5]+nb[7]+nb[8];
if(t<m)
{
m=t;
str="CGB";
}
t=nb[0]+nb[2]+nb[5]+nb[4]+nb[6]+nb[7];
if(t<m)
{
m=t;
str="GBC";
}
t=nb[0]+nb[2]+nb[3]+nb[4]+nb[7]+nb[8];
if(t<m)
{
m=t;
str="GCB";
}
if(str!=null)System.out.println(str+" "+m);
}
return 0;
}
}