首页 > 其他 > 详细

将整数100 随机分成 10段

时间:2015-05-08 14:32:47      阅读:291      评论:0      收藏:0      [点我收藏+]
static void Main(string[] args)
        {
            int[] a=new int[101];
            Random r = new Random();
            int IntervalCount=10;             

            int count = 0;
            while(count<IntervalCount-1)
            {
                int v = r.Next(99) + 1;
                if (a[v] == 1) continue;
                else
                {
                    a[v] = 1;
                    count++;
                }
            }
            a[100] = 1;
            
            int flag = 0;
            int totalCount = 0;
            for (int i = 1; i <= 100; i++)
            {
                if (a[i] == 0) continue;
                else
                {
                    Console.WriteLine(flag.ToString()+"-"+i.ToString()+".span="+(i-flag).ToString());
                    totalCount++;

                    flag = i;
                }
            }
            Console.WriteLine("lines=>" + totalCount.ToString());
            Console.ReadKey();

            
        }

 

将整数100 随机分成 10段

原文:http://www.cnblogs.com/zzPrince/p/4487343.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!