#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <algorithm>
using namespace std;
struct vv
{
char s[20];
int id;
}v[10005];
int cnt=0;
int cmp(struct vv x,struct vv y)
{
return strlen(x.s)<strlen(y.s);
}
int cmp2(struct vv x,struct vv y)
{
return x.id<y.id;
}
void judge(char *s)
{
vector<struct vv> test;
int num=strlen(s);
test.clear();
for(int i=0;i<cnt;i++)
{
if(!strcmp(s,v[i].s)) {printf("%s is correct\n",s);return;}
if(strlen(v[i].s)==num||strlen(v[i].s)==num-1||strlen(v[i].s)==num+1)
{
test.push_back(v[i]);
}
}
sort(test.begin(),test.end(),cmp2);
int ok=0;
printf("%s: ",s);
for(int i=0;i<test.size();i++)
{
if(strlen(test[i].s)==num-1)
{
int ok=0;
for(int j=0;j<num;j++)
{
if(ok==0&&test[i].s[j]==s[j])
continue;
if(ok==1&&test[i].s[j-1]==s[j])
continue;
else
{
if(ok==0) ok=1;
else {ok=2;break;}
}
}
if(ok!=2) printf("%s ",test[i].s);
}
if(strlen(test[i].s)==num)
{
int count=0;
for(int j=0;j<num;j++)
if(test[i].s[j]==s[j]) count++;
if(count==num-1)
printf("%s ",test[i].s);
}
if(strlen(test[i].s)==num+1)
{
int ok=0;
for(int j=0;j<num+1;j++)
{
if(ok==0&&test[i].s[j]==s[j])
continue;
if(ok==1&&test[i].s[j]==s[j-1])
continue;
else
{
if(ok==0) ok=1;
else {ok=2;break;}
}
}
if(ok!=2) printf("%s ",test[i].s);
}
}
printf("\n");
}
int main()
{
char temp[20];
while(true)
{
scanf("%s",temp);
if(!strcmp(temp,"#")) break;
else {
strcpy(v[cnt].s,temp);
v[cnt].id=cnt;
cnt++;
}
}
sort(v,v+cnt,cmp);
struct vv check[55];
while(true)
{
scanf("%s",temp);
if(!strcmp(temp,"#")) break;
else judge(temp);
}
return 0;
}

硬着头皮写下去就OK了。

主要思维量在于少一个字母和多一个字母的情况,

自己的分析还是对的。就是略掉这个字母看继续比较后面的。

不过裸写的速度不够快,二分的思想自己应着重练一下。

POJ1035的更多相关文章

  1. POJ1035——Spell checker(字符串处理)

    Spell checker DescriptionYou, as a member of a development team for a new spell checking program, ar ...

  2. poj1035 Spell checker

    这题目比较简单,把思路搞清楚就可以啦. #include <stdio.h> #include <string.h> +][]; int init(){ ; while(~sc ...

  3. POJ1035&&POJ3080&&POJ1936

    字符串处理专题,很早就写好了然而忘记写blog了 1035 题意:给你一些单词作为字典.然后让你查找一些单词.对于每个单词,如果在字典中就输出它.否则输出所有它通过删除||增加||替换一个字符能得到的 ...

  4. poj分类 很好很有层次感。

    初期: 一.基本算法:      (1)枚举. (poj1753,poj2965)      (2)贪心(poj1328,poj2109,poj2586)      (3)递归和分治法.      ( ...

  5. 【转】POJ题目分类推荐 (很好很有层次感)

    OJ上的一些水题(可用来练手和增加自信) (poj3299,poj2159,poj2739,poj1083,poj2262,poj1503,poj3006,poj2255,poj3094)初期: 一. ...

  6. 【转】ACM训练计划

    [转] POJ推荐50题以及ACM训练方案 -- : 转载自 wade_wang 最终编辑 000lzl POJ 推荐50题 第一类 动态规划(至少6题, 和 必做) 和 (可贪心) (稍难) 第二类 ...

  7. POJ 题目分类(转载)

    Log 2016-3-21 网上找的POJ分类,来源已经不清楚了.百度能百度到一大把.贴一份在博客上,鞭策自己刷题,不能偷懒!! 初期: 一.基本算法: (1)枚举. (poj1753,poj2965 ...

  8. (转)POJ题目分类

    初期:一.基本算法:     (1)枚举. (poj1753,poj2965)     (2)贪心(poj1328,poj2109,poj2586)     (3)递归和分治法.     (4)递推. ...

  9. acm常见算法及例题

    转自:http://blog.csdn.net/hengjie2009/article/details/7540135 acm常见算法及例题  初期:一.基本算法:     (1)枚举. (poj17 ...

随机推荐

  1. Codeforces 650 D. Zip-line

    $ >Codeforces \space 650 D. Zip-line<$ 题目大意 : 有一个长度为 \(n\) 的序列 \(h\) ,\(m\) 次询问,每一次询问求如果把序列中第 ...

  2. 51nod2000 四边形分割平面 规律题

    观察样例,$ans(1) = 1, ans(2) = 10$,再手推一组,$ans(3) = 26$ 可以发现规律$ans(n) = (2n - 1)^2 + 1$ 如果还是没看出规律,那么打个程序去 ...

  3. [BZOJ4887][TJOI2017]可乐(DP+矩阵快速幂)

    题目描述 加里敦星球的人们特别喜欢喝可乐.因而,他们的敌对星球研发出了一个可乐机器人,并且放在了加里敦星球的1号城市上.这个可乐机器人有三种行为: 停在原地,去下一个相邻的城市,自爆.它每一秒都会随机 ...

  4. BZOJ 2428 JZYZOJ1533 : [HAOI2006]均分数据 模拟退火 随机化

    http://www.lydsy.com/JudgeOnline/problem.php?id=2428 http://172.20.6.3/Problem_Show.asp?id=1533 http ...

  5. POJ 3764 The xor-longest Path trie树解决位运算贪心

    http://poj.org/problem?id=3764 题意 :  一颗树,每个边有个值,在树上找一条简单路径,使得这条路径上的边权异或值最大 先找到所有节点到一点的距离 , 显然dis( x ...

  6. HDU 6119 小小粉丝度度熊(Two pointers)

    [题目链接] http://acm.hdu.edu.cn/showproblem.php?pid=6119 [题目大意] 给出一些签到区间和一些补签卡,问可以创造的最长连续签到区间 [题解] 如果我们 ...

  7. bzoj 1008 组合计数

    正难则反 前面定后面就定->枚举开头 /************************************************************** Problem: 1008 ...

  8. VK Cup 2016 - Qualification Round 2 C. Road Improvement dfs

    C. Road Improvement 题目连接: http://www.codeforces.com/contest/638/problem/C Description In Berland the ...

  9. Could not open JDBC Connection for transaction; nested exception is java.sql.SQLException: Connectio

    严重: StandardWrapper.Throwableorg.springframework.transaction.CannotCreateTransactionException: Could ...

  10. cocos2d-x 环境搭建

        刚搬到博客园,第一次在这写博.有点小激动啊~~     闲话不多说,这次想做一个专题,针对最近比较流行的手游开发引擎cocos2d-x,希望大家不吝赐教~     本节主要针对环境搭建方面进行 ...