回复 10楼 qq1023569223
c答案看起来不方便,这两题难吗?我感觉还行,虽然做不出,怎么要这么多代码。。。
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(); } } }
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(); } } }