摘要: public static void SetArray(int[] arrayint) { // int[] arrayint = new int[100]; Random random = new Random(); for (int i = 1; i <= 1000; i++) { int index = random.Next(0, 1000); if (arrayint[index] == 0) arrayint[index] = i; else i--; } foreach (int i in arrayint) { Console.Write(i); Console.Writ 阅读全文
posted @ 2013-08-25 16:53 爱起早的小D 阅读(201) 评论(0) 推荐(0) 编辑
摘要: //输出重复的元素 public static void ArrayDuplicate(int[] array1) { //string[] array1 = new string[] { "7ss", "4s", "7g", "1a","4g", "1e", "5e", "2a", "5e" }; ArrayList list1 = new ArrayList(); //储存去重后剩余的元素 ArrayList l 阅读全文
posted @ 2013-08-25 16:50 爱起早的小D 阅读(447) 评论(0) 推荐(0) 编辑
摘要: //从数列1,2,3.......n 中 随意取几个数,使其和等于 m public static void Print(int n, int m, List list = null) { if (n childList = new List(); if (list != null) { childList.AddRange(list); } childList.Add(i); Print(i - 1, m - i, childList); } else if (i == m) { if (list != null) { foreach (int j in list) { Console... 阅读全文
posted @ 2013-08-25 16:49 爱起早的小D 阅读(223) 评论(0) 推荐(0) 编辑
摘要: //求子数组的最大和 public static int maxSubarray(int[] a, int size) { if (size max) { max = sum; } else if (sum maxSum) maxSum = curSum; } if (maxSum == 0) { //若是数组中的元素均为负数,则输出里面的最大元素 maxSum = array[0]; //当然这步也可以写到上面一个循环里 for (int i = 1; i < size; i++) { if (maxSum < array[i]) maxSum = array[i]; } } r 阅读全文
posted @ 2013-08-25 16:48 爱起早的小D 阅读(159) 评论(0) 推荐(0) 编辑
摘要: //求n个数中的最小k个数 public static void TestMin(int k, int n) { Random rd = new Random(); int[] myArray = new int[n]; int[] newArray = new int[k]; for (int i = 0; i myArray[j]) { continue; } else { newArray[0] = myArray[j]; Array.Sort(newArray); } } foreach (int i in newArray) Console.WriteLine(i); } 阅读全文
posted @ 2013-08-25 16:47 爱起早的小D 阅读(283) 评论(0) 推荐(0) 编辑
摘要: //例如输入字符串abc,则输出由字符a、b、c 所能排列出来的所有字符串 public static void AllArray(string str, string str2 = "") { if (str == null) return; if (str == string.Empty) Console.WriteLine(str2); for (int i = 0; i n2 ? n1 : n2; m = n1 % n2; n1 = n2; n2 = m; } min = Mul / n1; Console.WriteLine(n1); Console.WriteL 阅读全文
posted @ 2013-08-25 16:44 爱起早的小D 阅读(441) 评论(0) 推荐(0) 编辑
摘要: using System;using System.Collections.Generic;using System.Text;namespace ConsoleApplication2{ public class SuanFa { //求十进制数转换2进制后会有几个1 public static int Number1(int n) { //n = Convert.ToInt32(Console.ReadLine()); int x = 0; while (true) { while (n != 0) { if ((n & 1) == 1) x++; n = n >> 1 阅读全文
posted @ 2013-08-25 16:43 爱起早的小D 阅读(414) 评论(0) 推荐(0) 编辑
摘要: using System;using System.Collections.Generic;using System.Text;using System.Collections;namespace ConsoleApplication2{ class StringSuan { //字符串是否包含问题 A中的字符是否在B中出现 public static void Contains() { string str1 = "ggwahrah"; string str2 = "gwha"; // 开辟一个辅助数组并清零 int[] hash = new int[ 阅读全文
posted @ 2013-08-25 16:41 爱起早的小D 阅读(393) 评论(0) 推荐(1) 编辑
摘要: 第一篇博客就整理下排序算法吧 ,欢迎大家批评指正using System;using System.Collections.Generic;using System.Text;namespace ConsoleApplication2{ class Sort { //二分查找 public static int Search(int[] data, int val) { if (data.Length middle && j > left) j--; if (i left) QuickSearch(dataArray, left, j); if (i array[j]) 阅读全文
posted @ 2013-08-25 16:31 爱起早的小D 阅读(214) 评论(0) 推荐(0) 编辑