所以我和一个朋友有一个问题,我们找不到答案。
给出一个长度或大小未知的字符串,用乱码覆盖,请注意一个或两个字符可能会拼写错误。是否有可能弄清楚那个词应该是什么。
一个例子:我们有一个字典['apple','banana','potato]
是否有可能找到这些单词中是否没有一个,像这样的字符串:
alxcsfapple saodpjkasf(或者可能像这样的amncbxanana一样拼写错误
他认为唯一的方法就是n!但是,我们是否可以通过使用一种自动更正的形式来优化此方法,该形式假定每个字母后的新单词的开头以及非n的trie!办法? 这是NP问题吗?
答案 0 :(得分:1)
可以使用修改后的Levenshtein distance指标在import org.hibernate.Criteria;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
@Transactional
public int changepassword(String password, long mobile) {
// TODO Auto-generated method stub
session = factory.getCurrentSession();
Query query = session.createQuery("update User u set u.password='" + password + "' where u.mobile=" + mobile);
int result = query.executeUpdate();
return result;
}
add this code 200% it will work... might scenario is diff but write like this:)
时间内完成此搜索:即,将干草的第零行初始化为零(这意味着我们可以从索引的任何位置开始干草免费)。所以这不是NP。
有关详细信息,请参见https://en.wikipedia.org/wiki/Approximate_string_matching#Problem_formulation_and_algorithms和http://ginstrom.com/scribbles/2007/12/01/fuzzy-substring-matching-with-levenshtein-distance-in-python/。