POJ1035
#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的更多相关文章
- POJ1035——Spell checker(字符串处理)
Spell checker DescriptionYou, as a member of a development team for a new spell checking program, ar ...
- poj1035 Spell checker
这题目比较简单,把思路搞清楚就可以啦. #include <stdio.h> #include <string.h> +][]; int init(){ ; while(~sc ...
- POJ1035&&POJ3080&&POJ1936
字符串处理专题,很早就写好了然而忘记写blog了 1035 题意:给你一些单词作为字典.然后让你查找一些单词.对于每个单词,如果在字典中就输出它.否则输出所有它通过删除||增加||替换一个字符能得到的 ...
- poj分类 很好很有层次感。
初期: 一.基本算法: (1)枚举. (poj1753,poj2965) (2)贪心(poj1328,poj2109,poj2586) (3)递归和分治法. ( ...
- 【转】POJ题目分类推荐 (很好很有层次感)
OJ上的一些水题(可用来练手和增加自信) (poj3299,poj2159,poj2739,poj1083,poj2262,poj1503,poj3006,poj2255,poj3094)初期: 一. ...
- 【转】ACM训练计划
[转] POJ推荐50题以及ACM训练方案 -- : 转载自 wade_wang 最终编辑 000lzl POJ 推荐50题 第一类 动态规划(至少6题, 和 必做) 和 (可贪心) (稍难) 第二类 ...
- POJ 题目分类(转载)
Log 2016-3-21 网上找的POJ分类,来源已经不清楚了.百度能百度到一大把.贴一份在博客上,鞭策自己刷题,不能偷懒!! 初期: 一.基本算法: (1)枚举. (poj1753,poj2965 ...
- (转)POJ题目分类
初期:一.基本算法: (1)枚举. (poj1753,poj2965) (2)贪心(poj1328,poj2109,poj2586) (3)递归和分治法. (4)递推. ...
- acm常见算法及例题
转自:http://blog.csdn.net/hengjie2009/article/details/7540135 acm常见算法及例题 初期:一.基本算法: (1)枚举. (poj17 ...
随机推荐
- CodeForces 1063C. Dwarves, Hats and Extrasensory Abilities 交互
题目大意: 依次给定$n$个点的颜色,要求给定这$n$个点的坐标以及一条可以把他们分成两部分的直线 强制在线(交互) $n \leqslant 30$ 感觉自己真像一个乱搞... 我们只考虑把点放在最 ...
- [BZOJ4444][SCOI2015]国旗计划(倍增)
链上是经典贪心问题,将线段全按左端点排序后把点全撒在线段右端点上.这里放到环上,倍长即可. 题目保证不存在区间包含情况,于是有一种暴力做法,先将战士的管辖区间按左端点从小到大排序,对于询问x,从x战士 ...
- [HDU5965]扫雷
[HDU5965]扫雷 题目大意: 一个\(3\times n(n\le10000)\)的扫雷,第\(2\)排没有雷.告诉你第\(2\)排上的数,问有几种埋雷的方案? 思路: 动态规划. 将\(1,3 ...
- bzoj 1715: [Usaco2006 Dec]Wormholes 虫洞 -- spfa判断负环
1715: [Usaco2006 Dec]Wormholes 虫洞 Time Limit: 5 Sec Memory Limit: 64 MB 注意第一次加边是双向边第二次是单向边,并且每次询问前数 ...
- lucas定理 FOJ 2020 组合
Problem 2020 组合 Accept: 886 Submit: 2084Time Limit: 1000 mSec Memory Limit : 32768 KB Problem ...
- CC1101是一种低成本真正单片的UHF收发器
CC1101是一种低成本真正单片的UHF收发器,为低功耗无线应用而设计.电路主要设定为在315.433.868和915MHz的ISM(工业,科学和医学)和SRD(短距离设备)频率波段,也可以容易地设置 ...
- NativeXml: A native Delphi XML parser and writer
http://www.simdesign.nl/xml.html This software component contains a small-footprint Object Pascal (D ...
- mysql 监控工具
zabbix和grafana是绝配. pmm的prometheus太占资源了
- Appium+python自动化13-native和webview切换
前言 现在大部分app都是混合式的native+webview,对应native上的元素通过uiautomatorviewer很容易定位到,webview上的元素就无法识别了. 一.识别webview ...
- redis的主从配置 扩容
由于redis的集群功能没有完全编写好,见:http://redis.io/topics/cluster-spec 集群只有测试版的第8个版本redis3.0.0 见 http://redis.io/ ...