将多个学生平均分配到多个学校的方法示例

int[] studentIds = new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20 };//学生
            int[] schoolIds = new int[] { 1, 2 };//学校

            for (int i = 0; i < studentIds.Length; i++)
            {
                Console.WriteLine("studentId:" + studentIds[i]);
                if (i <= schoolIds.Length - 1)
                {
                    Console.WriteLine("schoolId:" + schoolIds[i]);
                }
                else
                {
                    Console.WriteLine("schoolId:" + schoolIds[i % schoolIds.Length]);
                }
            }

 

posted @ 2020-06-08 14:54  雨V幕  阅读(375)  评论(0)    收藏  举报