POJ 1035问题解答
#include <iostream>
#include <cstdio>
#include <cmath>
#include <string>
#include <vector>
using namespace std;
bool compSameLen(char* first, char* second)
{
char* pCur = first;
int cnt = 0;
while (*pCur)
{
char* ret = strchr(second, *pCur);
if (ret)
{
cnt++;
}
pCur++;
}
if (cnt == strlen(first) - 1)
{
return true;
}
return false;
}
bool compLessLen(char* buf, char* dictStr)
{
char* pCur = buf;
int cnt = 0;
while (*pCur)
{
char* ret = strchr(dictStr, *pCur);
if (ret)
{
cnt++;
}
pCur++;
}
if (cnt == strlen(buf))
{
return true;
}
return false;
}
bool compMoreLen(char* buf, char* dictStr)
{
char* pCur = dictStr;
int cnt = 0;
while (*pCur)
{
char* ret = strchr(buf, *pCur);
if (ret)
{
cnt++;
}
pCur++;
}
if (cnt == strlen(dictStr))
{
return true;
}
return false;
}
int main()
{
vector<string> dict;
char buf[32];
while (true)
{
gets_s(buf);
if (strcmp(buf, "#") == 0)
{
break;
}
dict.push_back(buf);
}
while (true)
{
gets_s(buf);
if (strcmp(buf, "#") == 0)
{
break;
}
char dictStr[32];
vector<string> replaceStrs;
for (int i = 0; i < dict.size(); i++)
{
strcpy_s(dictStr, dict[i].c_str());
if (strcmp(buf, dictStr) == 0)
{
printf("%s is correct\n",buf);
goto GH;
}
int curLen = strlen(buf);
int dictLen = strlen(dictStr);
if (curLen == dictLen)
{
bool ret = compSameLen(buf,dictStr);
if (ret)
{
replaceStrs.push_back(dictStr);
}
}
else if (curLen == dictLen - 1)
{
bool ret = compLessLen(buf,dictStr);
if (ret)
{
replaceStrs.push_back(dictStr);
}
}
else if (curLen == dictLen + 1)
{
bool ret = compMoreLen(buf,dictStr);
if (ret)
{
replaceStrs.push_back(dictStr);
}
}
}
if (replaceStrs.empty())
{
printf("%s:", buf);
}
else
{
char output[256];
sprintf_s(output, "%s:", buf);
for (int k = 0; k < replaceStrs.size(); k++)
{
strcat_s(output, " ");
strcat_s(output, replaceStrs[k].c_str());
}
printf("%s", output);
}
GH:continue;
}
}
POJ 1035问题解答的更多相关文章
- POJ 1035 代码+具体的目光
Spell checker Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 19319 Accepted: 7060 Descri ...
- poj 1035
http://poj.org/problem?id=1035 poj的一道字符串的水题,不难,但就是细节问题我也wa了几次 题意就是给你一个字典,再给你一些字符,首先如果字典中有这个字符串,则直接输出 ...
- poj 1035 Spell checker(水题)
题目:http://poj.org/problem?id=1035 还是暴搜 #include <iostream> #include<cstdio> #include< ...
- poj 1035 Spell checker(hash)
题目链接:http://poj.org/problem?id=1035 思路分析: 1.使用哈希表存储字典 2.对待查找的word在字典中查找,查找成功输出查找成功信息 3.若查找不成功,对word增 ...
- POJ 1035 Spell checker 字符串 难度:0
题目 http://poj.org/problem?id=1035 题意 字典匹配,单词表共有1e4个单词,单词长度小于15,需要对最多50个单词进行匹配.在匹配时,如果直接匹配可以找到待匹配串,则直 ...
- POJ 1035 Spell checker(串)
题目网址:http://poj.org/problem?id=1035 思路: 看到题目第一反应是用LCS ——最长公共子序列 来求解.因为给的字典比较多,最多有1w个,而LCS的算法时间复杂度是O( ...
- poj 1035 Spell checker ( 字符串处理 )
Spell checker Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 16675 Accepted: 6087 De ...
- poj 1035 Spell checker
Spell checker Time Limit: 2000 MS Memory Limit: 65536 KB 64-bit integer IO format: %I64d , %I64u J ...
- 【POJ 1035】Spell checker
题 题意 每个单词,如果字典里存在,输出”该单词 is correct“:如果字典里不存在,但是可以通过删除.添加.替换一个字母得到字典里存在的单词,那就输出“该单词:修正的单词”,并按字典里的顺序输 ...
随机推荐
- jdk+myeclipse配置安装相关步骤
1.JDK的安装JDK 版本:7u25 安装路径:c:\java(注意:装不装公共jre都可,自己可以选择安装到哪里)环境变量配置:(1)JAVA_HOME:C:\Java(就是你安装jdk的目录 ...
- Ctrl+Shift+F12切换最大化编辑器
常用快捷键(keymaps:Default情况下) Esc键编辑器(从工具窗口) F1帮助千万别按,很卡! F2(Shift+F2)下/上高亮错误或警告快速定位 F3向下查找关键字出现位置 F4查找变 ...
- 短语密码(blowfish_secret)的设置
简单的说,phpmyadmin就是一种mysql的管理工具,安装该工具后,即可以通过web形式直接管理mysql数据,而不需要通过执行系统命令来管理,非常适合对数据库操作命令不熟悉的数据库管理者,下面 ...
- 【液晶模块系列基础视频】2.虚拟U盘
[液晶模块系列基础视频]2.虚拟U盘 ============================== 技术论坛:http://www.eeschool.org 博客地址:http://xiaomagee ...
- 循环btn上面的视图
#import "ViewController.h" @interface ViewController () @end @implementation ViewControlle ...
- 如何开发ecshop支付插件
如何开发ecshop支付插件 ecshop模板网 / 2014-06-03 目标一:搞懂ecshop的支付流程 选完商品,进入购物车页面,点击“结算中心”,页面跳转到flow.php?step=che ...
- 大话数据结构(八)Java程序——双向链表的实现
线性链表--双向链表 双向链表定义: 双向链表(double linked list): 是在单表单的每个结点中,再设置一个指向前驱结点的指针域.因此,在双向链表中的结点都有两个指针域,一个指向前驱, ...
- phone number is not known @w@ have no phone, and thus no phone number
http://dev.mysql.com/doc/refman/5.7/en/problems-with-null.html B.5.4.3 Problems with NULL Values The ...
- Listener-监听器+ServletContext+ApplicationContext
参考资料 ServletContext和ApplicationContext有什么区别 ServletContext:是web容器的东西, 一个webapp一个, 比session作用范围要大, 从中 ...
- C#委托初探
委托是一种定义方法签名的类型,可以与具有兼容签名的任何方法关联.您可以通过委托调用其中已添加的方法列表.委托用于将方法作为参数传递给其他方法.事件处理程序就是通过委托调用的方法.您可以创建一个自定义方 ...