words

Converting words to numbers in c++

三世轮回 提交于 2019-12-04 19:47:22
I have problem converting words into numbers like Five Thousand Six Hundred Thirty two - 5632 I don't even know how to start if someone has done it please guide me how to do it... Here, i did it in python, it will help you or someone else from algorithmic perspective. #!/usr/bin/python __author__ = 'tomcat' all = { "one" : 1, "two" : 2, "three" : 3, "four" : 4, "five" : 5, "six" : 6, "seven" : 7, "eight" : 8, "nine" : 9, "ten" : 10, "eleven": 11, "twelve": 12, "thirteen": 13, "fourteen": 14, "fifteen": 15, "sixteen": 16, "seventeen": 17, "eighteen": 18, "nineteen": 19, "twenty" : 20, "thirty"

[LC] 318. Maximum Product of Word Lengths

江枫思渺然 提交于 2019-12-04 16:45:06
Given a string array words , find the maximum value of length(word[i]) * length(word[j]) where the two words do not share common letters. You may assume that each word will contain only lower case letters. If no such two words exist, return 0. Example 1: Input: ["abcw","baz","foo","bar","xtfn","abcdef"] Output: 16 Explanation: The two words can be "abcw", "xtfn". Example 2: Input: ["a","ab","abc","d","cd","bcd","abcd"] Output: 4 Explanation: The two words can be "ab", "cd". Example 3: Input: ["a","aa","aaa","aaaa"] Output: 0 Explanation: No such pair of words. class Solution { public int

Placing words in table grid in word search puzzle?

一笑奈何 提交于 2019-12-04 12:22:45
I am trying to create a words search puzzle generated by script. The words should be placed horizontally, vertically or diagonally. I might need the option to set whether they are allowed to read only forward or backward. I have an array of words such as (apple, banana, grape, lemon, pear) which needs to be placed in the table. I have already created the table but I am stuck at how to place the words in the grid. I am looking for examples with some explanation. Please see my code below: var wordsList =[ "apple", "banana", "grape", "lemon", "pear" ]; var cells = 10; // Numbers of cells

Finding the most popular words in a list

故事扮演 提交于 2019-12-04 11:50:24
问题 I have a list of words: words = ['all', 'awesome', 'all', 'yeah', 'bye', 'all', 'yeah'] And I want to get a list of tuples: [(3, 'all'), (2, 'yeah'), (1, 'bye'), (1, 'awesome')] where each tuple is... (number_of_occurrences, word) The list should be sorted by the number of occurrences. What I've done so far: def popularWords(words): dic = {} for word in words: dic.setdefault(word, 0) dic[word] += 1 wordsList = [(dic.get(w), w) for w in dic] wordsList.sort(reverse = True) return wordsList The

Python stemmer issue: wrong stem

两盒软妹~` 提交于 2019-12-04 06:56:05
问题 Hi i'm trying to stem words with a python stemmer, i tried Porter and Lancaster, but they have the same problem. They can't stem correclty words that end with "er" or "e". for example, they stem computer --> comput rotate --> rotat this is a part of the code line=line.lower() line=re.sub(r'[^a-z0-9 ]',' ',line) line=line.split() line=[x for x in line if x not in stops] line=[ porter.stem(word, 0, len(word)-1) for word in line] # or 'line=[ st.stem(word) for word in line]' return line any idea

Can I tell if a std::string represents a number using stringstream?

倖福魔咒の 提交于 2019-12-04 03:36:12
Apparently this is suposed to work in showing if a string is numerical, for example "12.5" == yes, "abc" == no. However I get a no reguardless of the input. std::stringstream ss("2"); double d; ss >> d; if(ss.good()) {std::cout<<"number"<<std::endl;} else {std::cout<<"other"<<std::endl;} You should use an istringstream so that it knows it's trying to parse input. Also, just check the result of the extraction directly rather than using good later. #include <sstream> #include <iostream> int main() { std::istringstream ss("2"); double d = 0.0; if(ss >> d) {std::cout<<"number"<<std::endl;} else

how to generate list of (unique) words from text file in ubuntu?

五迷三道 提交于 2019-12-04 03:13:59
I have an ASCII text file. I want to generate a list of all "words" from that file using one or more Ubuntu commands. A word is defined as an alpha-num sequence between delimiters. Delimiters are by default whitespaces but I also want to experiment with other characters like punctuation etc. IN other words, i want to be able to specify a delimiter char set. How do I produce only a unique set of words? What if I also want to list only those words that are at least N characters long? You could use grep: -E '\w+' searches for words -o only prints the portion of the line that matches % cat temp

Cassandra full text search like

怎甘沉沦 提交于 2019-12-03 13:52:53
Let's say I have a column family named Questions like below: Questions = { Who are you: { username: "user1" }, What is the answer: { username: "user1" }... } How do I search for all the questions that contain certain words? Get all questions that contain 'what' word. How do I do it using python or at least Java? DNA Solandra ( https://github.com/tjake/Solandra ) is the new name for Lucandra. Solandra is a combination of Cassandra and Solr (which is based on the Lucene full-text search engine). Cassandra alone doesn't tackle text-search, although you could implement some basic text indexing by

How to break long words in a table td?

心不动则不痛 提交于 2019-12-03 08:51:01
问题 This is what I have: <td style='width:500px; white-space: pre-wrap; white-space: -moz-pre-wrap; white-space: -pre-wrap; white-space: -o-pre-wrap; word-wrap: break-word;'> 回答1: I think this solution will help you! pre { white-space: pre; /* CSS 2.0 */ white-space: pre-wrap; /* CSS 2.1 */ white-space: pre-line; /* CSS 3.0 */ white-space: -pre-wrap; /* Opera 4-6 */ white-space: -o-pre-wrap; /* Opera 7 */ white-space: -moz-pre-wrap; /* Mozilla */ white-space: -hp-pre-wrap; /* HP Printers */ word

Finding the most popular words in a list

梦想的初衷 提交于 2019-12-03 07:25:14
I have a list of words: words = ['all', 'awesome', 'all', 'yeah', 'bye', 'all', 'yeah'] And I want to get a list of tuples: [(3, 'all'), (2, 'yeah'), (1, 'bye'), (1, 'awesome')] where each tuple is... (number_of_occurrences, word) The list should be sorted by the number of occurrences. What I've done so far: def popularWords(words): dic = {} for word in words: dic.setdefault(word, 0) dic[word] += 1 wordsList = [(dic.get(w), w) for w in dic] wordsList.sort(reverse = True) return wordsList The question is... Is it Pythonic, elegant and efficient? Are you able to do it better? Thanks in advance.