avatar
T*8
1
You have a sentence with several words with spaces removed and the words
have their character order shuffled. You have a dictionary to lookup. Write
an algorithm to produce the original sentence back with spaces and words
with normal character order
avatar
j*y
2
两个word之间不会 shuffled吧? 感觉和anagram的题目有点类似,
产生的 original sentence可能不会唯一
vector > func(string s, int start)
{
vector > result;
if(start == s.length())
{
return result;
}
for(int i = start; i < s.length(); ++i)
{
vector word = anagramWordsInDictionary(s.substr(start,
i - start + 1));
if(word.size() > 0)
{
vector > tmp = func(s, i + 1);
if((i == s.length() - 1)
{
for(int j = 0; j < word.size(); ++j)
{
result.push_back(vector(1, word[j]));
}
}
if(tmp.size() > 0)
{
for(int j = 0; j < word.size(); ++j)
for(int k = 0; k < tmp.size(); ++k)
{
vector setence = tmp
[k];
sentence.insert(sentence.
begin(), word[j]);
result.push_back(sentence);
}
}
}
}
return result;
}

Write

【在 T*****8 的大作中提到】
: You have a sentence with several words with spaces removed and the words
: have their character order shuffled. You have a dictionary to lookup. Write
: an algorithm to produce the original sentence back with spaces and words
: with normal character order

相关阅读
logo
联系我们隐私协议©2024 redian.news
Redian新闻
Redian.news刊载任何文章,不代表同意其说法或描述,仅为提供更多信息,也不构成任何建议。文章信息的合法性及真实性由其作者负责,与Redian.news及其运营公司无关。欢迎投稿,如发现稿件侵权,或作者不愿在本网发表文章,请版权拥有者通知本网处理。