题目传送门

一道暴力可以过的水题。(直接暴力模拟的那种)

但是我打Trie练练模板,但是TMD因为数组开太小卡了好久。

code:

#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <map>
#include <algorithm>
using namespace std; struct trie{
int tr[][],cnt,v[];
trie(){memset(tr,,sizeof tr),memset(v,,sizeof v),cnt=;}
void add(string a)
{
int now=,len=a.size();
for(int i=;i<len;i++){
if(!tr[now][a[i]-'a'])tr[now][a[i]-'a']=++cnt,now=cnt;
else now=tr[now][a[i]-'a'];
}
v[now]=;
} int query(string a)
{
int now=,len=a.size(),o=;
for(int i=;i<len;i++){
if(!tr[now][a[i]-'a'])return ;
now=tr[now][a[i]-'a'];
}
return v[now];
}
}M; map<string,int>MP;
struct node{
string f;int id;
node(){f="";id=;}
}as[];
string S,ks,t;
int tot=;
inline int cmp(node x,node y){return x.id<y.id;}
int main()
{
// freopen("x.txt","r",stdin);
t="";
int ide=;
while(cin>>S,S[]!='#'){if(MP[S])continue;M.add(S);MP[S]=++ide;}
while(cin>>S,S[]!='#'){
if(M.query(S)){
cout<<S;cout<<" is correct";puts("");
}
else{
tot=;
cout<<S<<':';
int len=S.size();
for(int i=;i<len;i++){
for(int j=;j<;j++){
t=S[i];
ks=j+'a';
S.erase(i,),S.insert(i,ks);
if(M.query(S))
as[++tot].f=S,as[tot].id=MP[S];
S.erase(i,),S.insert(i,t);
}
}
for(int i=;i<=len;i++){
for(int j=;j<;j++){
ks=j+'a';
S.insert(i,ks);
if(M.query(S))
as[++tot].f=S,as[tot].id=MP[S];
S.erase(i,);
}
}
for(int i=;i<len;i++){
t=S[i];
S.erase(i,);
if(M.query(S))
as[++tot].f=S,as[tot].id=MP[S];
S.insert(i,t);
}
sort(as+,as+tot+,cmp);
for(int i=;i<=tot;i++)
if(as[i].f!=as[i-].f)
cout<<' '<<as[i].f;
puts("");
}
}
}

POJ1035_Spell checker_KEY的更多相关文章

随机推荐

  1. D3——Updates, Transitions, and Motion

    <script type="text/javascript"> ; ; ; , , , , , , , , , ,, , , , , , , , , ]; //crea ...

  2. BZOJ 1051 受欢迎的牛 缩点

    题目链接: https://www.lydsy.com/JudgeOnline/problem.php?id=1051 题目大意: 每一头牛的愿望就是变成一头最受欢迎的牛.现在有N头牛,给你M对整数( ...

  3. Webserver管理系列:12、开启关闭Ping命令

    有些时候站点打开速度会非常慢,我们要排查故障所在.须要用到Ping命令.可是Windows Server 2008防火墙默认是关闭Ping的 我们能够通过下面方法开启Ping 打开防火墙->高级 ...

  4. 【php】获取ip

    addBoard.php中获取到ip $ip=$_SERVER['REMOTE_ADDR']; 通过ajax采取POST方式发送到服务器 $("#submit").on(" ...

  5. WEB安全 php+mysql5注入防御(二)

    第四天: 一.新的注入函数: ascii() substring("string",n,m)                     n>=1 limit n,m      ...

  6. ES6标准入门 字符串的扩展

    1:模板字符串与模板引擎 https://blog.csdn.net/crper/article/details/52940625 es6模板字符串中标签模板作为参数时产生空元素的问题 https:/ ...

  7. nginx中文文档

    http://www.nginx.cn/doc/ LNMP :https://lnmp.org/faq/lnmp-vhost-add-howto.html 配置详解 配置详解2

  8. JS页面刷新

    setTimeout('location.reload()',1000);//页面刷新 1000为延时的毫秒数 1.setInterval() - 间隔指定的毫秒数不停地执行指定的代码.   2.se ...

  9. XMPP备忘笔记

    xmpp中文翻译计划: http://wiki.jabbercn.org/%E9%A6%96%E9%A1%B5 XEP-0004: 数据表单 摘要: 本文定义了一个XMPP扩展协议用于数据表单,可以用 ...

  10. 用PSCP在Windows和Linux之间相互传输文件

    在Linux服务器之间相互传文件我们常用 scp命令,但是在Linux和Windows之间相互传输就不那么直接了. 使用 Putty的 PSCP 则会简单的多 1. 下载 http://www.chi ...