题目传送门

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

但是我打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. python不用正则过渡括号

  2. pop链构造

    class Person { private $name; private $sex; private $age; //__set()方法用来设置私有属性 function __set($proper ...

  3. xss练习平台及writeup

    今天玩了一天的xss. 分享几个xss game https://xss.haozi.me/#/0x00 http://47.94.13.75/test/  writeup:http://www.cn ...

  4. nextjs-demo

    这个是根据nextjs服务端渲染做的一个小demo 关键性代码,主要是控制模态框显示隐藏 关于index页面 //index.js /* eslint-disable jsx-a11y/anchor- ...

  5. 一般处理程序中,获取session

    注意了: 1.要在一般处理程序中获取其他页面的session值,需要引用名空间: using System.Web.SessionState; 2.然后继承一个接口:IRequiresSessionS ...

  6. VC++6.0中碰到Cannot access the ClassView information file.ClassView information will not be avaible.的解决方法

    一般情况下是由于类视图文件损坏了,这是经常会发生的现象. 解决步骤: 1.关闭工程,2.删除工程下.clw .ncb 文件及/debug目录,3.重建工程build all. 具体解释如下: dsp ...

  7. mixup: Beyond Empirical Risk Minimization

    这篇论文MIT和FAIR的工作,主要是提出了一种mixup的方式.(感觉是一种产生hard sample的方法,是一种新的.更有效的数据增强.) 1 Introduction 大网络需要大数据,目前C ...

  8. PAT——1062. 最简分数

    一个分数一般写成两个整数相除的形式:N/M,其中M不为0.最简分数是指分子和分母没有公约数的分数表示形式. 现给定两个不相等的正分数 N1/M1 和 N2/M2,要求你按从小到大的顺序列出它们之间分母 ...

  9. DBA手记(学习)-library cache pin

    select sid,event,p1raw from v$session_wait where event like 'library cache pin%'; select sql_text fr ...

  10. 有关集合的foreach循环里的add/remove

    转自:Hollis(微信号:hollischuang) 在阿里巴巴Java开发手册中,有这样一条规定: 但是手册中并没有给出具体原因,本文就来深入分析一下该规定背后的思考. 1 .foreach循环 ...