您的位置:首页 > 其它

分支-05. 用天平找小球

2014-09-12 16:59 197 查看
三个球A、B、C,大小形状相同且其中有一个球与其他球重量不同。要求找出这个不一样的球。

输入格式:输入在一行中给出3个正整数,顺序对应球A、B、C的重量。

输出格式:在一行中输出唯一的那个不一样的球。

输入样例:1 1 2输出样例:C

import java.util.Scanner;
public class Main
{
public static void main(String[] args)
{
Scanner ball = new Scanner(System.in);
String balls = ball.nextLine();
String[] b = balls.split(" ");
if(b.length == 3)
{
int b1 = Integer.parseInt(b[0]);
int b2 = Integer.parseInt(b[1]);
int b3 = Integer.parseInt(b[2]);
if(b1==b2 || b1==b3 || b2==b3)
{
if(b1==b2)
System.out.print("C");
else
{
if(b1==b3)
System.out.print("B");
else
System.out.print("A");
}
}
else
System.out.print("Input error!");
}
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: