ToolsUtils.cs 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. namespace CB.Web.tool_old
  5. {
  6. public class ToolsUtils
  7. {
  8. public static int GetWSCount(string[] Number)
  9. {
  10. int result = 0;
  11. for (int i = 0; i < Number.Length; i++)
  12. {
  13. for (int j = i + 1; j < Number.Length; j++)
  14. {
  15. if (Convert.ToInt32(Number[i]) % 10 == Convert.ToInt32(Number[j]) % 10)
  16. result++;
  17. }
  18. }
  19. return 6 - result;
  20. }
  21. public static int GetLHCount(string[] Number)
  22. {
  23. int lh = 0;
  24. for (int i = 0; i < Number.Length; i++)
  25. {
  26. if (i > 0 && Convert.ToInt32(Number[i]) - Convert.ToInt32(Number[i - 1]) == 1)
  27. lh++;
  28. }
  29. return lh;
  30. }
  31. public static string GetZHB(string[] Number)
  32. {
  33. int z = 0;
  34. for (int i = 0; i < Number.Length; i++)
  35. {
  36. if (Convert.ToInt32(Number[i]) == 1 || Convert.ToInt32(Number[i]) == 2 || Convert.ToInt32(Number[i]) == 3 || Convert.ToInt32(Number[i]) == 5 || Convert.ToInt32(Number[i]) == 7 || Convert.ToInt32(Number[i]) == 11 || Convert.ToInt32(Number[i]) == 13 || Convert.ToInt32(Number[i]) == 17 || Convert.ToInt32(Number[i]) == 19 || Convert.ToInt32(Number[i]) == 23 || Convert.ToInt32(Number[i]) == 29 || Convert.ToInt32(Number[i]) == 31)
  37. z++;
  38. }
  39. return z.ToString() + ":" + (Number.Length - z).ToString();
  40. }
  41. public static string GetDXB(string[] Number)
  42. {
  43. return GetDXB(Number, 16);
  44. }
  45. public static string GetDXB(string[] Number, int maxmin)
  46. {
  47. int d = 0;
  48. for (int i = 0; i < Number.Length; i++)
  49. {
  50. if (Convert.ToInt32(Number[i]) > maxmin)
  51. d++;
  52. }
  53. return d.ToString() + ":" + (Number.Length - d).ToString();
  54. }
  55. public static string GetJOB(string[] Number)
  56. {
  57. int o = 0;
  58. for (int i = 0; i < Number.Length; i++)
  59. {
  60. if (Convert.ToInt32(Number[i]) % 2 == 0)
  61. o++;
  62. }
  63. return (Number.Length - o).ToString() + ":" + o.ToString();
  64. }
  65. public static int GetAC(string[] kjh)
  66. {
  67. List<string> result = GetCombination(kjh, 2);
  68. ArrayList acarray = new ArrayList();
  69. int tpac = 0;
  70. for (int i = 0; i < result.Count; i++)
  71. {
  72. string[] tp = result[i].Split(',');
  73. int tmp = Math.Abs(Convert.ToInt32(tp[0]) - Convert.ToInt32(tp[1]));
  74. if (!acarray.Contains(tmp))
  75. {
  76. tpac++;
  77. acarray.Add(tmp);
  78. }
  79. }
  80. return tpac - (kjh.Length - 1);
  81. }
  82. public static List<string> GetCombination(string[] data, int count)
  83. {
  84. Dictionary<string, int> dic = new Dictionary<string, int>();
  85. List<string> output = new List<string>();
  86. for (int i = 0; i < data.Length; i++)
  87. {
  88. dic.Add(data[i], i);
  89. }
  90. SelectN(dic, data, count, 1, ref output);
  91. return output;
  92. }
  93. private static void SelectN(Dictionary<string, int> dd, string[] data, int count, int times, ref List<string> output)
  94. {
  95. Dictionary<string, int> dic = new Dictionary<string, int>();
  96. foreach (KeyValuePair<string, int> kv in dd)
  97. {
  98. for (int i = kv.Value + 1; i < data.Length; i++)
  99. {
  100. if (times < count - 1)
  101. {
  102. dic.Add(kv.Key + "," + data[i], i);
  103. }
  104. else
  105. {
  106. output.Add(kv.Key + "," + data[i]);
  107. }
  108. }
  109. }
  110. times++;
  111. if (dic.Count > 0)
  112. {
  113. SelectN(dic, data, count, times, ref output);
  114. }
  115. }
  116. public static ArrayList zuheFilter(ArrayList Number)
  117. {
  118. ArrayList tempNumber = new ArrayList();
  119. ArrayList numArray = new ArrayList();
  120. string num = string.Empty;
  121. for (int i = 0; i < Number.Count; i++)
  122. {
  123. numArray.Clear();
  124. for (int a = 0; a < Number[i].ToString().Length; a++)
  125. {
  126. numArray.Add(Number[i].ToString().Substring(a, 1));
  127. }
  128. numArray.Sort();
  129. num = numArray[0].ToString() + numArray[1].ToString() + numArray[2].ToString();
  130. if (!tempNumber.Contains(num.ToString()))
  131. tempNumber.Add(num);
  132. }
  133. Number.Clear();
  134. Number = tempNumber;
  135. return Number;
  136. }
  137. public static ArrayList zuhe3Filter(ArrayList Number, int zuhe3)
  138. {
  139. ArrayList tempNumber = new ArrayList();
  140. int t1 = 0;
  141. int t2 = 0;
  142. int t3 = 0;
  143. for (int i = 0; i < Number.Count; i++)
  144. {
  145. t1 = Convert.ToInt32(Number[i].ToString().Substring(0, 1));
  146. t2 = Convert.ToInt32(Number[i].ToString().Substring(1, 1));
  147. t3 = Convert.ToInt32(Number[i].ToString().Substring(2, 1));
  148. if ((t1 == t2 || t2 == t3 || t1 == t3) && zuhe3 == 0 && !(t1 == t2 && t2 == t3))
  149. {
  150. }
  151. else
  152. {
  153. tempNumber.Add(Number[i]);
  154. }
  155. }
  156. Number.Clear();
  157. Number = tempNumber;
  158. return Number;
  159. }
  160. public static ArrayList zuhe6Filter(ArrayList Number, int zuhe6)
  161. {
  162. ArrayList tempNumber = new ArrayList();
  163. int t1 = 0;
  164. int t2 = 0;
  165. int t3 = 0;
  166. for (int i = 0; i < Number.Count; i++)
  167. {
  168. t1 = Convert.ToInt32(Number[i].ToString().Substring(0, 1));
  169. t2 = Convert.ToInt32(Number[i].ToString().Substring(1, 1));
  170. t3 = Convert.ToInt32(Number[i].ToString().Substring(2, 1));
  171. //组六
  172. if (t1 != t2 && t2 != t3 && t1 != t3 && zuhe6 == 0)
  173. { }
  174. else
  175. { tempNumber.Add(Number[i]); }
  176. }
  177. Number.Clear();
  178. Number = tempNumber;
  179. return Number;
  180. }
  181. public static ArrayList zuhebFilter(ArrayList Number, int zuheb)
  182. {
  183. ArrayList tempNumber = new ArrayList();
  184. int t1 = 0;
  185. int t2 = 0;
  186. int t3 = 0;
  187. for (int i = 0; i < Number.Count; i++)
  188. {
  189. t1 = Convert.ToInt32(Number[i].ToString().Substring(0, 1));
  190. t2 = Convert.ToInt32(Number[i].ToString().Substring(1, 1));
  191. t3 = Convert.ToInt32(Number[i].ToString().Substring(2, 1));
  192. //过滤豹子
  193. if (t1 == t2 && t2 == t3 && t1 == t3 && zuheb == 0)
  194. { }
  195. else
  196. { tempNumber.Add(Number[i]); }
  197. }
  198. Number.Clear();
  199. Number = tempNumber;
  200. return Number;
  201. }
  202. }
  203. }