屁屁的新玩具# pets - 心有所宠
j*7
1 楼
http://www.yodlecareers.com/puzzles/triangle.html
我的答案不对 (665321)。
public static void main(String[] args) {
// TODO Auto-generated method stub
File file = new File("triangle.txt");
try
{
BufferedReader in = new BufferedReader(new FileReader(file));
String line;
int value=Integer.parseInt(in.readLine().trim());
int index=0;
while ((line = in.readLine()) != null) {
String [] temp=line.split("[ ]");
int a=Integer.parseInt(temp[index]);
int b=Integer.parseInt(temp[index+1]);
if(b>a)
{
index=index+1;
value+=b;
}
else
{
value+=a;
}
}
System.out.println(value);//665321
in.close();
}catch(IOException e )
{
}
}
我的答案不对 (665321)。
public static void main(String[] args) {
// TODO Auto-generated method stub
File file = new File("triangle.txt");
try
{
BufferedReader in = new BufferedReader(new FileReader(file));
String line;
int value=Integer.parseInt(in.readLine().trim());
int index=0;
while ((line = in.readLine()) != null) {
String [] temp=line.split("[ ]");
int a=Integer.parseInt(temp[index]);
int b=Integer.parseInt(temp[index+1]);
if(b>a)
{
index=index+1;
value+=b;
}
else
{
value+=a;
}
}
System.out.println(value);//665321
in.close();
}catch(IOException e )
{
}
}