分支-05. 用天平找小球

三个球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!");
        } 
    }
}

 

posted @ 2014-09-12 16:59  winTeaer  阅读(236)  评论(0编辑  收藏  举报