新生——S型分班算法
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 | package org.zttc.service; public class DistributeClass { public static final Boolean order = true ; public static void main(String[] args) { //把分班后数据存入二位数组 int test[][] = divideByClass( 64 , 8 ,order); String str = "顺序" ; if (!order){ str = "倒序" ; } for ( int i= 0 ;i< 8 ;i++){ for ( int j= 0 ;j<test[i].length;j++){ int x = test[i][j]; if (x != 0 ){ System.out.println( "进行" +str+ "排列的结果:第" +(i+ 1 )+ "班被分配的第" +(j+ 1 )+ "位学生总体排名为:" +x+ "" ); } } } } public static int [][] divideByClass( int stuNum, int classNum, boolean type){ //定义一个二维数组,初始化容量为 stuNum=64 classNum=8 ,int[8][9] int [][] rs = new int [classNum][stuNum/classNum+ 1 ]; for ( int i= 0 ;i<stuNum;i++){ //i<64 int x = i%classNum; //求余 64/8 0 1 2 3 4 5 6 7 横坐标 int y = i/classNum; //整除 64/8 0 1 2 3 4 5 6 7 8 纵坐标 //求余x=0,整除y!=0的时候,type取反 if (x== 0 && y!= 0 ){ // 8-false 16-true 24-false 32-true 40-false 48-true 56-true 64-false type=!type; } if (!type){ x = classNum-i%classNum- 1 ; //班级数-序号%班级数-1 y = i/classNum; //序号/班级数 } rs[x][y]=i+ 1 ; /** x求余 y整除 rs数组 * i=0;x=0;y=0;type=true,rs[0][0]=1; * i=1;x=1;y=0;type=true,rs[1][0]=2; * i=2;x=2;y=0;type=true,rs[2][0]=3; * i=3;x=3;y=0;type=true,rs[3][0]=4; * i=4;x=4;y=0;type=true,rs[4][0]=5; * i=5;x=5;y=0;type=true,rs[5][0]=6; * i=6;x=6;y=0;type=true,rs[6][0]=7; * i=7;x=7;y=0;type=true,rs[7][0]=8; * i=8;x=6;y=1;type=false,rs[6][1]=9; * i=9;x=6;y=1;type=false,rs[7][1]=10; * i=10;x= */ } return rs; } } |
· 一个费力不讨好的项目,让我损失了近一半的绩效!
· .NET Core 托管堆内存泄露/CPU异常的常见思路
· PostgreSQL 和 SQL Server 在统计信息维护中的关键差异
· C++代码改造为UTF-8编码问题的总结
· DeepSeek 解答了困扰我五年的技术问题
· 一个费力不讨好的项目,让我损失了近一半的绩效!
· 清华大学推出第四讲使用 DeepSeek + DeepResearch 让科研像聊天一样简单!
· 实操Deepseek接入个人知识库
· CSnakes vs Python.NET:高效嵌入与灵活互通的跨语言方案对比
· Plotly.NET 一个为 .NET 打造的强大开源交互式图表库