123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717 |
- using Common;
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace Common
- {
- public static class CzDataHelper
- {
- #region 值的计算
- public static bool IsCf(string code)
- {
- var list = code.Split('+')[0].Split(',').ToList();
- if (list.GroupBy(i => i).Where(g => g.Count() > 1).Count() >= 1)
- return true;
- return false;
- }
- #region 和值相关
-
-
-
-
-
- public static int GetHz(string code)
- {
- var list = code.Split('+')[0].Split(',').ToList();
- if (code.IsEmpty())
- return 0;
- return list.Sum(p => p.TryToInt32());
- }
-
-
-
-
-
- public static string GetHzDxValue(int hz)
- {
- if (GetHzDx(hz) == 1)
- {
- return "大";
- }
- return "小";
- }
- #endregion
-
-
-
-
-
- public static int GetKd(string code)
- {
- var list = code.Split('+')[0].Split(',').ToList().OrderByDescending(p => p);
- if (code.IsEmpty())
- return 0;
- return list.FirstOrDefault().TryToInt32() - list.LastOrDefault().TryToInt32();
- }
-
-
-
-
-
- public static int GetAc(string code)
- {
- var list = code.Split('+')[0].Split(',').ToList().OrderByDescending(p => p);
- List<string> result = GetCombination(list.ToArray(), 2);
- ArrayList acarray = new ArrayList();
- int tpac = 0;
- for (int i = 0; i < result.Count; i++)
- {
- string[] tp = result[i].Split(',');
- int tmp = Math.Abs(Convert.ToInt32(tp[0]) - Convert.ToInt32(tp[1]));
- if (!acarray.Contains(tmp))
- {
- tpac++;
- acarray.Add(tmp);
- }
- }
- return tpac - (list.Count() - 1);
- }
-
-
-
-
-
- public static int GetHw(int hz)
- {
- return hz % 10;
- }
-
-
-
-
-
- public static string GetDxValue(int value)
- {
- if (GetDx(value) == 1)
- {
- return "大";
- }
- return "小";
- }
-
-
-
-
-
- public static string GetDsValue(int value)
- {
- if (value % 2 != 0)
- {
- return "单";
- }
- return "双";
- }
-
-
-
-
-
- public static string Get012Value(int value)
- {
- if (value % 3 == 0)
- {
- return "0";
- }
- else if (value % 3 == 1)
- {
- return "1";
- }
- return "2";
- }
- #region 形态
-
-
-
-
-
- public static string GetXtDxValue(string code)
- {
- var result = "";
- code.Split(',').ToList().ForEach(p =>
- {
- if (GetDx(int.Parse(p)) == 1)
- {
- result += "大";
- }
- else
- {
- result += "小";
- }
- });
- return result;
- }
-
-
-
-
-
- public static string GetXtDsValue(string code)
- {
- var result = "";
- code.Split(',').ToList().ForEach(p =>
- {
- if (int.Parse(p) % 2 != 0)
- {
- result += "单";
- }
- else
- {
- result += "双";
- }
- });
- return result;
- }
-
-
-
-
-
- public static string GetXt012Value(string code)
- {
- var result = "";
- code.Split(',').ToList().ForEach(p =>
- {
- if (int.Parse(p) % 3 == 0)
- {
- result += "0";
- }
- else if (int.Parse(p) % 3 == 1)
- {
- result += "1";
- }
- else
- {
- result += "2";
- }
- });
- return result;
- }
- #endregion
-
-
-
-
-
- public static string GetZx(string value)
- {
- var list = value.Split(',').ToList();
- if (list.Count < 3)
- {
- list = new List<string>();
- foreach (var item in value)
- {
- list.Add(item.ToString());
- }
- }
- list = list.Where(p => !string.IsNullOrEmpty(p.Trim())).Select(p => p.Trim()).ToList();
- if (list.GroupBy(p => p).Count() == 1)
- {
- return "豹子";
- }
- else if (list.GroupBy(p => p).Count() == 2)
- {
- return "组三";
- }
- return "组六";
- }
-
-
-
-
-
- public static string GetJob(string code)
- {
- var list = code.Split('+')[0].Split(',').ToList();
- var j = 0;
- var o = 0;
- list.ForEach(p =>
- {
- if (int.Parse(p) % 2 == 0)
- {
- j++;
- }
- else
- o++;
- });
- return $"{j}:{o}";
- }
-
-
-
-
-
-
- public static string GetDxb(string code, int n)
- {
- var z = n / 2;
- var d = 0;
- var x = 0;
- code.GetCode().ForEach(p =>
- {
- if (d >= z)
- d++;
- else
- x++;
- });
- return $"{d}:{x}";
- }
-
- #region 组合算法
-
-
-
-
-
-
- public static List<string> GetCombination(string[] data, int count)
- {
- Dictionary<string, int> dic = new Dictionary<string, int>();
- List<string> output = new List<string>();
- for (int i = 0; i < data.Length; i++)
- {
- dic.Add(data[i], i);
- }
- SelectN(dic, data, count, 1, ref output);
- return output;
- }
-
-
-
-
-
-
-
-
- public static void SelectN(Dictionary<string, int> dd, string[] data, int count, int times, ref List<string> output)
- {
- Dictionary<string, int> dic = new Dictionary<string, int>();
- foreach (KeyValuePair<string, int> kv in dd)
- {
- for (int i = kv.Value + 1; i < data.Length; i++)
- {
- if (times < count - 1)
- {
- dic.Add(kv.Key + "," + data[i], i);
- }
- else
- {
- output.Add(kv.Key + "," + data[i]);
- }
- }
- }
- times++;
- if (dic.Count > 0)
- {
- SelectN(dic, data, count, times, ref output);
- }
- }
- #endregion
- #endregion
- #region 是有计算
- #region 大小相关方法
-
-
-
-
-
- private static int GetHzDx(int n)
- {
- return GetDxBymiddle(n, 14);
- }
-
-
-
-
-
-
-
- private static int GetDx(int n)
- {
- return GetDxBymiddle(n, 5);
- }
-
-
-
-
-
-
- private static int GetDxBymiddle(int n, int middle)
- {
- int r = 1;
- if (n < middle)
- r = 0;
- return r;
- }
-
-
-
-
-
-
- private static string GetDxb(List<int> kjh, int middle)
- {
- int d = 0;
- int x = 0;
- for (int i = 0; i < kjh.Count; i++)
- {
- if (GetDxBymiddle(kjh[i], middle) == 1)
- d++;
- else
- x++;
- }
- return d.ToString() + ":" + x.ToString();
- }
- #endregion
- #endregion
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- }
- }
|