| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 10940 人关注过本帖
标题:有一个已经排好序的数组。现输入一个数,要求按原来的规律将它插入数组中。
只看楼主 加入收藏
学好好要饭
Rank: 1
等 级:新手上路
帖 子:19
专家分:0
注 册:2016-5-4
收藏
得分:0 
回复 10楼 qq1023569223
c答案看起来不方便,这两题难吗?我感觉还行,虽然做不出,怎么要这么多代码。。。
2016-05-04 19:51
学好好要饭
Rank: 1
等 级:新手上路
帖 子:19
专家分:0
注 册:2016-5-4
收藏
得分:0 
调式了下,这答案,溜溜溜。。。。。。
2016-05-04 19:52
yhlvht
Rank: 13Rank: 13Rank: 13Rank: 13
等 级:贵宾
威 望:36
帖 子:707
专家分:4405
注 册:2011-9-30
收藏
得分:0 
这么热闹,我也来一个
程序代码:
using System;
using System.Collections.Generic;
using System.Linq;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] arrInt = new int[] { 1, 5, 7, 8, 34, 56, 78, 89 };
            int insertNumber = Int32.Parse(Console.ReadLine());
            List<int> list = arrInt.ToList<int>();
            list.Add(insertNumber);
            IEnumerable<int> list1 = list.OrderBy<int, int>((t) => { return t; });
            arrInt = list1.ToArray<int>();
            foreach (int i in arrInt)
            {
                Console.Write(i + " ");
            }
            Console.Read();
        }
    }
}
2016-05-04 20:15
yhlvht
Rank: 13Rank: 13Rank: 13Rank: 13
等 级:贵宾
威 望:36
帖 子:707
专家分:4405
注 册:2011-9-30
收藏
得分:0 
程序代码:
using System;
using System.Collections.Generic;
using System.Linq;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] arrInt = new int[] { 12, 2, 8, 22, 16, 4, 10, 6, 14, 20 };
            int count = 0;
            int num = Start(arrInt, ref count);
            Console.WriteLine("count={0},result={1}", count, num);
            Console.ReadKey();
        }

        static int Start(int[] arrInt, ref int count)
        {
            IEnumerable<int> ie = arrInt.Select<int, int>((t) => { return t / 2; });
            List<int> list = ie.ToList<int>();
            list.Insert(0, list[list.Count - 1]);
            list.RemoveAt(list.Count - 1);
            IEnumerable<int> arrInt1 = ie.Zip<int, int, int>(list, (t, t1) => { return t + t1; });
            arrInt1 = arrInt1.Select<int, int>((t) =>
            {
                if (t % 2 != 0)
                    return ++t;
                else
                    return t;
            });
            count++;
            int i = arrInt1.ToArray<int>()[0];
            if (!arrInt1.All<int>((t) => { return t == i; }))
            {
                display(arrInt1.ToArray<int>(), count);
                i = Start(arrInt1.ToArray<int>(), ref count);
            }
            return i;
        }

        static void display(int[] a, int cnt)
        {
            int i = 0;
            Console.Write("{0}>>>>>", cnt);
            for (; i < 10; ++i) Console.Write("{0} ", a[i]);
            Console.WriteLine();
        }
    }
}
2016-05-04 22:10
快速回复:有一个已经排好序的数组。现输入一个数,要求按原来的规律将它插入数组 ...
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.018386 second(s), 9 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved