最长边截短为:其它两边之和减一

拼凑三角形

http://www.nowcoder.com/questionTerminal/d9f5dbd3b57d450e8406e102573d4bdd

最长边大于其它两边之和的话,就截短为其它两边之和减一的长度:

import java.util.*;
public class Main {
    public static void main(String[] args) throws Exception{
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt(), b = sc.nextInt(), c = sc.nextInt();
        int sum = a + b + c;
        int A = Math.max(Math.max(a, b), c);
        if(A >= sum - A) System.out.println(2*(sum - A) - 1);
        else System.out.println(sum);
    }
}
全部评论

相关推荐

想按时下班的我在等o...:我投测试也是这个情况,不知道咋办了
点赞 评论 收藏
分享
评论
1
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务