[ad_1]
Hello everyone, please and need your help. I have three text boxes on the windows form: - In tetxBox1.Text there is a dictionary with many words (the longest words have 12 letters) - There are always 12 letters offered in textBox2.Text - In textBox3.Text, I want the result to be longest word from textBox1 composed of offered words from textBox2 For example: In textBox1.Text I have the following words: characters character charity act acter acted successfully wind succession windy successful window windows success excellent excel excellence excellency In textBox2.Text I have following 12 letters offered: euclsfcysuls In textBox3.Text I want as result longest word from textBox1.Text than words from textBox2.Text: successfully I am asking for your help if it is possible, some solution... I hope you understood me, I apologize for my English if you didn't understand. Thank you all in advance.
https://i.postimg.cc/HnS59c2R/Capture.png[^]
मैंने क्या प्रयास किया है:
static bool isSubSequence(String str1, String str2) { int m = str1.Length, n = str2.Length; int j = 0; for (int i = 0; i < n && j < m; i++) { if (str1[j] == str2[i]) { j++; } } return (j == m); } static String findLongestString(List<String> dict, String str) { String result = ""; int length = 0; foreach (String word in dict) { if (length < word.Length && isSubSequence(word, str)) { result = word; length = word.Length; } } return result; } private void btnfind_Click(object sender, EventArgs e) { String[] arr = textBox1.Lines; List<String> dict = new List<String>(arr); String str = textBox2.Text; textBox3.Text = (findLongestString(dict, str)); }
[ad_2]
コメント