题解 | 最大的组合

最大的组合

https://www.nowcoder.com/practice/d9c79e3ee3a141bfb008c1433e4f329b

import java.util.LinkedList;
import java.util.List;
import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        List<int[]> ans = new LinkedList<>();
        int max = 0;
        for (int a = 0; a <= n; a++) {
            for (int b = 0; b <= n; b++) {
                if ((a + b) % 3 != 0) continue;
                for (int c = 0; c <= n; c++) {
                    if ((b + c) % 5 == 0 && (a + b + c) % 7 == 0) {
                        if (a + b + c > max) {
                            max = a + b + c;
                            ans.clear();
                            ans.add(new int[]{a, b, c});
                        } else if (a + b + c == max) ans.add(new int[]{a, b, c});
                    }
                }
            }
        }
        for (int[] res : ans) System.out.println(res[0] + " " + res[1] + " " + res[2]);
        sc.close();
    }
}

全部评论

相关推荐

昨天 19:16
已编辑
福建农林大学 测试开发
求好运眷顾🙏🏻:翻译:面试前没盘点好hc一下面太多了,现在在排序回去等通知
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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