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(); }
时间: 2024-10-15 00:50:14