zoukankan      html  css  js  c++  java
  • Java实现运动员分组

    有N个人参加100米短跑比赛。跑道为8条。程序的任务是按照尽量使每组的人数相差最少的原则分组。
    例如:
    N=8时,分成1组即可。
    N=9时,分成2组:一组5人,一组4人。
    N=25时,分4组:7、6、6、6。

    请编程计算分组数字。
    要求从标准输入获得一个正整数(1~100之间,不必考虑输入错误的情况),表示参赛的人数。
    程序输出每个组的人数。从大到小顺序输出,每个数字一行。

    比如,
    用户输入:25
    程序输出:
    7
    6
    6
    6

    import java.util.Scanner;
    
    public class Main {
        
        
        public static void main(String[] args) {
            Scanner in = new Scanner(System.in);
            int n = in.nextInt();
            if(n % 8 == 0) {
                for(int i = 0;i < n / 8;i++)
                    System.out.println("8");
            } else {
                int count = n / 8 + 1;
                int r = n / count;
                int low = n - count * r;
                for(int i = 0;i < count;i++, low--) {
                    if(low > 0)
                        System.out.println((r + 1));
                    else
                        System.out.println(r);
                }
            }
        }
    }
    
  • 相关阅读:
    细说Cookie(转)
    Custom Exception in ASP.NET Web API 2 with Custom HttpResponse Message
    内核中的定时器
    ibus拼音安装_ubuntu10.04
    linux模块
    zebra/quagga线程分析
    vim常用配置
    rar安装和使用
    zebra/quagga
    netsnmp编译动态库
  • 原文地址:https://www.cnblogs.com/a1439775520/p/13077632.html
Copyright © 2011-2022 走看看