//DEMO <a target="_blank" href="http://download.csdn.net/detail/qq873113580/6033615">http://download.csdn.net/detail/qq873113580/6033615</a>
Using Microsoft. international. converters. pinYinConverter; using System. collections. generic; using System. collections. objectModel; using System. linq; using System. text; using System. text. regularExpressions; using System. threading. tasks; namespace ConsoleApplication1 {class Program {static void Main (string [] args) {List <string> ss = GetPYAll ("other "); // combine the output set with qi-ta ji-ta and then extract it.} // <summary> /// Obtain full join /// </summary> /// <param name = "str"> </param> /// <returns> returns a multi-tone set (for example: qita jita is returned for the input of "Others" in the original polyphonic word qi ji.) </returns> public static List <string> GetPYAll (string str) {List <string> soruceList = new List <string> (); // a List of Pinyin combinations <string> list = new List <string> (); // The pinyin collection Dictionary <int, List <string> dic = new Dictionary <int, List <string> (); char [] chars = str. toCharArray (); for (int I = 0; I <chars. length; I ++) {List <string> tempList = new List <string> (); if (new Regex (@ "^ [\ u4e00-\ u9fa5] + $ "). match (chars [I]. toString ()). success) {ChineseChar chineseChar = new ChineseChar (chars [I]); ReadOnlyCollection <string> pyColl = chineseChar. pinyins; // The Cartesian product of the first letter is generated cyclically and stored in the temporary pinyin list foreach (var item in pyColl) {if (item! = Null) {string temp = item. Remove (item. Length-1, 1); list. Add (temp); if (! TempList. contains (temp) {tempList. add (temp) ;}}} else // {tempList. add (chars [I]. toString (); list. add (chars [I]. toString ();} dic. add (I, tempList);} // combined List <string []> lst_Combination = PermutationAndCombination <string>. getCombination (list. toArray (), str. length); // obtain the foreach (string [] strs in lst_Combination) {bool B = false; for (int I = 0; I <strs. length; I ++) {if (dic [I]. contains (strs [I]) {B = true;} else {B = false; break;} if (B) {soruceList. add (string. join ("-", strs) ;}return soruceList ;}}}
Using System; using System. collections. generic; using System. linq; using System. text; using System. threading. tasks; namespace ConsoleApplication1 {public class PermutationAndCombination <T> {// <summary> // exchange two variables /// </summary> // <param name = "a"> variable 1 </param> /// <param name = "B"> variable 2 </param> public static void Swap (ref T, ref T B) {T temp = a; a = B; B = temp;} // <summary> // recursive algorithm to find the combination of arrays (Private Members) /// </summary> /// <param name = "list"> returned Model </param> /// <param name = "t"> array </ param> /// <param name = "n"> auxiliary variable </param> /// <param name = "m"> auxiliary variable </param> // <param name = "B"> secondary array </param> // <param name = "M"> secondary variable M </param> private static void GetCombination (ref List <T []> list, T [] t, int n, int m, int [] B, int M) {for (int I = n; I> = m; I --) {B [m-1] = I-1; if (m> 1) {GetCombination (ref list, t, I-1, m-1, B, M );} else {if (list = null) {list = new List <T []> ();} T [] temp = new T [M]; for (int j = 0; j <B. length; j ++) {temp [j] = t [B [j];} list. add (temp) ;}}/// <summary> // recursive algorithm for sorting (Private member) /// </summary> /// <param name = "list"> returned list </param> /// <param name = "t"> array </param> /// <param name = "startIndex"> start label </param> /// <param name = "endIndex"> end label </param> private static void GetPermutation (ref List <T []> list, T [] t, int startIndex, int endIndex) {if (startIndex = endIndex) {if (list = null) {list = new List <T []> ();} T [] temp = new T [t. length]; t. copyTo (temp, 0); list. add (temp);} else {for (int I = startIndex; I <= endIndex; I ++) {Swap (ref t [startIndex], ref t [I]); getPermutation (ref list, t, startIndex + 1, endIndex); Swap (ref t [startIndex], ref t [I]) ;}} /// <summary> /// sort the start and end labels, other elements remain unchanged /// </summary> /// <param name = "t"> array </param> /// <param name = "startIndex"> Start number </param> /// <param name = "endIndex"> end label </param> /// <returns> type from start label to end label </returns> public static List <T []> GetPermutation (T [] t, int startIndex, int endIndex) {if (startIndex <0 | endIndex> t. length-1) {return null;} List <T []> list = new List <T []> (); GetPermutation (ref list, t, startIndex, endIndex ); return list ;} /// <summary> /// return the full arrangement of all elements in the array /// </summary> /// <param name = "t"> array </param> /// <returns> fully-arranged paradigm </returns> public static List <T []> GetPermutation (T [] t) {return GetPermutation (t, 0, t. length-1 );} /// <summary> /// sort the n elements in the array /// </summary> /// <param name = "t"> array </param> /// <param name = "n"> Number of elements </param> /// arrange n elements in the <returns> array </returns> public static List <T []> GetPermutation (T [] t, int n) {if (n> t. length) {return null;} List <T []> list = new List <T []> (); List <T []> c = GetCombination (t, n ); for (int I = 0; I <c. count; I ++) {List <T []> l = new List <T []> (); GetPermutation (ref l, c [I], 0, n-1); list. addRange (l);} return list ;} /// <summary> /// evaluate the combination of n elements in the array /// </summary> /// <param name = "t"> obtain the array </param> /// <param name = "n"> Number of elements </param> /// the combination of n elements in the <returns> array. </returns> public static list <T []> GetCombination (T [] t, int n) {if (t. length <n) {return null;} int [] temp = new int [n]; List <T []> list = new List <T []> (); getCombination (ref list, t, t. length, n, temp, n); return list ;}}}