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 ...
随机推荐
- Javascript 中的神器
Promise in js 回调函数真正的问题在于他剥夺了我们使用 return 和 throw 这些关键字的能力.而 Promise 很好地解决了这一切. 2015 年 6 月,ECMAScript ...
- android 网络
韩梦飞沙 韩亚飞 313134555@qq.com yue31313 han_meng_fei_sha android - async - http 安卓 异步 超文本传输协议 xUtil a ...
- 【插头DP】hdu1964-Pipes
[题目大意] 给出一个网格,经过边要付出代价.求走过每一个格子的欧拉回路的最小代价.[思路] 裸裸的插头DP~然而写了好久orz [错误点] 整个人跟制杖了一样QAQ hash实力写挂…m和n搞反了. ...
- SpringBoot 如何从前台传递数组
1.SpringBoot 如何从前台传递数组 2.前台 $.ajax({ url: 'deleteBsGiftById', type: 'post', dataType: 'json', data: ...
- 【9.7校内测试】【二分+spfa】【最长上升子序列】【状压DP+贪心(?)】
刘汝佳蓝书上的题,标程做法是从终点倒着$spfa$,我是二分答案正着$spfa$判断可不可行.效果是一样的. [注意]多组数据建边一定要清零啊QAQ!!! #include<iostream&g ...
- hdu 5206 Four Inages Strategy 判断是否是正方形
Four Inages Strategy Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem. ...
- CentOS 6.9/7安装Parse+PostgreSQL
一.安装Parse-Server # npm install -g parse-server --unsafe-perm 备注:用--unsafe-perm参数的目的是使用了root权限进行安装. 二 ...
- 试了一把Intel的核显转码的威力
今天小试了一把Intel Cpu的核显转码的威力,确实非常快,使用的工具是MediaCoder,能达到10x的速度,效果非常明显,并且CPU占用非常低.为了比较,实用x264纯转同一个文件的,软编码能 ...
- 升压转换器 (Boost)
升压转换器 (Boost) 需要将输入电压转换为较高的输出电压时,升压转换器 (Boost)是唯一的选择. 升压转换器透过内部 MOSFET 对电压充电来达成升压输出的目的,而当 MOSFET 关闭时 ...
- printf回到上一行开头以及回到本行开头的方法
回到上一行开头 #include <stdio.h> #include <unistd.h> int main(void) { ; ){ printf("%d\n&q ...