C#基礎第三天-作業答案-集合-冒泡排序-類比名片

來源:互聯網
上載者:User

標籤:bsp   str   else   查詢   方法   排序   arraylist   名片   for   

1.冒泡排序   Console.WriteLine("對集合裡的數進行排序,請輸入第一個數:");            int a = int.Parse(Console.ReadLine());            Console.WriteLine("對集合裡的數進行排序,請輸入第二個數:");            int b = int.Parse(Console.ReadLine());            Console.WriteLine("對集合裡的數進行排序,請輸入第三個數:");            int c = int.Parse(Console.ReadLine());            Console.WriteLine("對集合裡的數進行排序,請輸入第四個數:");            int d = int.Parse(Console.ReadLine());            Console.WriteLine("對集合裡的數進行排序,請輸入第五個數:");            int e = int.Parse(Console.ReadLine());            int mid = 0;            List<int> iList = new List<int>();            iList.Add(a);            iList.Add(b);            iList.Add(c);            iList.Add(d);            iList.Add(e);            for (int i = 0; i<iList.Count; i++) {                for (int j = i + 1; j < iList.Count; j++) {                    if (iList[i] < iList[j]) {                        mid = iList[i];                        iList[i]=iList[j];                        iList[j] = mid;                    }                }            }            Console.WriteLine("排序後的結果為:");            foreach (int i1 in iList) {                Console.Write(i1+" ");            }2.  名片兩種集合:List集合:        List<Object> list = new List<Object>();            list.Add("社會安全號碼碼");            list.Add("電話號碼");            list.Add("性別");            list.Add("姓名");            list.Add("身高");            list.Add("年齡");            list.Add("體重");            List<Object> list1 = new List<Object>();            list1.Add("152103196312205230");            list1.Add("15998192408");            list1.Add("男");            list1.Add("劉夕饒");            list1.Add("172cm");            list1.Add("27歲");            list1.Add("75kg");            while (true) {                Console.Write("請輸入你要查詢的名字:");                string name = Console.ReadLine();                if (list1.Contains(name))                {                    foreach (Object obj in list)                    {                        Console.Write("   " + obj + " ");                    }                    Console.WriteLine();                    foreach (Object obj1 in list1)                    {                        Console.Write(obj1 + " ");                    }                    Console.WriteLine();                }                else                {                    Console.WriteLine("查無此人");                }ArrayList集合:  ///另一種方法            ArrayList Card = new ArrayList();            Card.Add(new ArrayList() { "220211100112209803", "13618390284", "男", "小胖", "178cm", "20", "200kg" });            Card.Add(new ArrayList() { "220211100112209803", "13618390284", "男", "石瑀", "178cm", "20", "200kg" });            Card.Add(new ArrayList() { "220211100112209803", "13618390284", "男", "張三", "178cm", "20", "200kg" });            Card.Add(new ArrayList() { "220211100112209803", "13618390284", "男", "李四", "178cm", "20", "200kg" });            Card.Add(new ArrayList() { "220211100112209803", "13618390284", "男", "李五", "178cm", "20", "200kg" });            Card.Add(new ArrayList() { "220211100112209803", "13618390284", "男", "李六", "178cm", "20", "200kg" });            string name = string.Empty;            Console.WriteLine("請輸入您要尋找的人名");            name = Console.ReadLine();            for (int i = 0; i < Card.Count; i++)            {                                ArrayList card = (ArrayList)Card[i];                        if(card.Contains(name) == true)                {                    Console.WriteLine(@"社會安全號碼:{0},電話號碼:{1},性別:{2},姓名:{3},身高:{4},年齡:{5},體重:{6}",                        card[0], card[1], card[2], card[3], card[4], card[5], card[6]);                    Console.ReadLine();                }                else                {                    continue;                }                 if (i == Card.Count - 1)                {                    Console.WriteLine("對不起,沒有您要找的人!");                    Console.WriteLine(" ");                    Console.ReadKey();                }            }

 

C#基礎第三天-作業答案-集合-冒泡排序-類比名片

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.