zoukankan      html  css  js  c++  java
  • 生产1100不重复随机数并排序

    using System;
    using System.Collections;

    namespace ConsoleApplication1
    {
        
    class Program
        {
            
    static void Main(string[] args)
            {
                
    int temp = 0;
                
    int[] intArr = new int[100];
                ArrayList myList 
    = new ArrayList();
                Random rnd 
    = new Random();
                
    while (myList.Count < 100)
                {
                    
    int num = rnd.Next(1101);
                    
    if (!myList.Contains(num))    // 这句是关键
                        myList.Add(num);
                }

                
    //
                
    //  转换为整形数组
                
                
    for (int i = 0; i < 100; i++)
                    intArr[i] 
    = (int)myList[i];

                
    //
                
    //  排序
                
                
    for (int i = 0; i < intArr.Length-1; i++)
                {
                    
    for (int j = 0; j < intArr.Length-1; j++)
                    {
                        
    if(intArr[j] > intArr[j+1])
                        {
                            temp 
    = intArr[j + 1];
                            intArr[j 
    + 1= intArr[j];
                            intArr[j] 
    = temp;
                        }
                    }
                }

                
    //
                
    //  输出

                
    for (int i = 0; i < intArr.Length; i++)
                {
                    Console.WriteLine(intArr[i].ToString());
                    
                }
                Console.Read();

            }
        }
    }
  • 相关阅读:
    ubuntu给手机建wifi
    ubuntu系统之难
    【百度之星2014~复赛 解题报告~正解】The Query on the Tree
    【百度之星2014~复赛)解题报告】The Query on the Tree
    【百度之星2014~初赛解题报告】
    【百度之星2014~初赛(第二轮)解题报告】JZP Set
    【百度之星2014~资格赛解题报告】
    【百度之星2014~初赛(第二轮)解题报告】Chess
    vi 中插入当前时间
    安装软件时依赖冲突的万能解决方案
  • 原文地址:https://www.cnblogs.com/Tonyyang/p/1435755.html
Copyright © 2011-2022 走看看