tag:blogger.com,1999:blog-3098638925089993315.post2702813941468700024..comments2023-04-26T19:21:06.970+05:30Comments on KodeKnight: Get Sentence from raw text Kinshuk Chandrahttp://www.blogger.com/profile/01344610750518430564noreply@blogger.comBlogger2125tag:blogger.com,1999:blog-3098638925089993315.post-27610224662177021202016-01-05T00:44:17.495+05:302016-01-05T00:44:17.495+05:30Thanks PaNThEra, I got that my code had issues. Th...Thanks PaNThEra, I got that my code had issues. Thank you so much for your working code. (Sorry for the delayed response)Kinshuk Chandrahttps://www.blogger.com/profile/01344610750518430564noreply@blogger.comtag:blogger.com,1999:blog-3098638925089993315.post-56871190100370603722015-12-06T05:21:34.443+05:302015-12-06T05:21:34.443+05:30DP Code Given Above Has Some Issue I Fixed It:
st...DP Code Given Above Has Some Issue I Fixed It:<br /><br />static boolean wordBreak(String str, Set tokenMap) {<br /> int size = str.length();<br /> if (size == 0) return true;<br /><br /> // Create the DP table to store results of subroblems. The value wb[i]<br /> // will be true if str[0..i-1] can be segmented into dictionary words,<br /> // otherwise false.<br /> boolean wb[] = new boolean[size + 1]; // default values are set to false<br /><br /><br /> for (int i = 1; i <= size; i++) {<br /> // if wb[i] is false, then check if current prefix can make it true.<br /> // Current prefix is "str.substr(0, i)"<br /> if (wb[i] == false && tokenMap.contains(str.substring(0, i)))<br /> wb[i] = true;<br /><br /> // wb[i] is true, then check for all subStrings starting from<br /> // (i+1)th character and store their results.<br /> if (wb[i] == true) {<br /> // If we reached the last prefix<br /> if (i == size)<br /> return true;<br /> for (int j = i ; j <=size; j++) {<br /> // Update wb[j] if it is false and can be updated<br /> // Note the parameter passed to tokenMap.contains() is<br /> // subString starting from index 'i' and length 'j-i'<br /> System.out.println(i+" "+j);<br /> if (wb[j] == false && tokenMap.contains(str.substring(i, j)))<br /> wb[j] = true;<br /><br /> // If we reached the last character<br /> if (j == size && wb[j] == true)<br /> return true;<br /> }<br /> }<br /> }<br /><br /> /* Uncomment these lines to print DP table "wb[]"<br /> for (int i = 1; i <= size; i++)<br /> out.print(wb[i]+" ") */<br /><br /> // If we have tried all prefixes and none of them worked<br /> return false;<br /> }PaNThErAhttps://www.blogger.com/profile/02704110034528790912noreply@blogger.com