#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问题解答的更多相关文章

  1. POJ 1035 代码+具体的目光

    Spell checker Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 19319 Accepted: 7060 Descri ...

  2. poj 1035

    http://poj.org/problem?id=1035 poj的一道字符串的水题,不难,但就是细节问题我也wa了几次 题意就是给你一个字典,再给你一些字符,首先如果字典中有这个字符串,则直接输出 ...

  3. poj 1035 Spell checker(水题)

    题目:http://poj.org/problem?id=1035 还是暴搜 #include <iostream> #include<cstdio> #include< ...

  4. poj 1035 Spell checker(hash)

    题目链接:http://poj.org/problem?id=1035 思路分析: 1.使用哈希表存储字典 2.对待查找的word在字典中查找,查找成功输出查找成功信息 3.若查找不成功,对word增 ...

  5. POJ 1035 Spell checker 字符串 难度:0

    题目 http://poj.org/problem?id=1035 题意 字典匹配,单词表共有1e4个单词,单词长度小于15,需要对最多50个单词进行匹配.在匹配时,如果直接匹配可以找到待匹配串,则直 ...

  6. POJ 1035 Spell checker(串)

    题目网址:http://poj.org/problem?id=1035 思路: 看到题目第一反应是用LCS ——最长公共子序列 来求解.因为给的字典比较多,最多有1w个,而LCS的算法时间复杂度是O( ...

  7. poj 1035 Spell checker ( 字符串处理 )

    Spell checker Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 16675   Accepted: 6087 De ...

  8. poj 1035 Spell checker

    Spell checker Time Limit: 2000 MS Memory Limit: 65536 KB 64-bit integer IO format: %I64d , %I64u   J ...

  9. 【POJ 1035】Spell checker

    题 题意 每个单词,如果字典里存在,输出”该单词 is correct“:如果字典里不存在,但是可以通过删除.添加.替换一个字母得到字典里存在的单词,那就输出“该单词:修正的单词”,并按字典里的顺序输 ...

随机推荐

  1. 用 Freemarker 生成 word 文档(包含图片)

    1. 用word写一个需要导出的word模板,然后存为xml格式. 2. 将xml中需要动态修改内容的地方,换成freemarker的标识符,例如: <w:p wsp:rsidR="0 ...

  2. string.h文件中函数用法

    下面为string.h文件中函数的详细用法: strcpy函数名:strcpy功 能: 拷贝一个字符串到另一个用 法: char *strcpy(char *destin, char *source) ...

  3. Spring对加载的bean之间循环依赖的处理

    根据下面文档的叙述,简言之: 对于相互之间通过构造函数注入相互循环依赖的情况,Spring会抛出BeanCurrentlyInCreationException错误. 如果AB两个beans是通过属性 ...

  4. How to: Fix a network printer suddenly showing as offline in Windows Vista, 7 or 8 « Robin's Blog

    This post has become quite popular – so I've updated it with a bit more detail, plus some people's e ...

  5. 8. Add the dashboard

    Controller Node: 1. sudo apt-get install apache2 memcached libapache2-mod-wsgi openstack-dashboard   ...

  6. JavaScript正则验证邮箱

    正则表达式/^正则$/.test() <html> <head> <title>JavaScript</title> <meta charset= ...

  7. laravel url() 和 asset() 的区别

    asset()方法用于引入 CSS/JavaScript/images 等文件,文件必须存放在public文件目录下.url()方法生成一个完整的网址.

  8. Android 通过网页打开自己的APP(scheme)

    Android 通过网页打开自己的APP(scheme) 分类: android2014-07-09 17:35 8565人阅读 评论(2) 收藏 举报 通过用手机的浏览器(内置,第三方都可)访问一个 ...

  9. 【IOS笔记】Creating Custom Content View Controllers

    Creating Custom Content View Controllers 自定义内容视图控制器 Custom content view controllers are the heart of ...

  10. A20的板子笔记

    除了串口可以登入控制台,还可以用SSH2. ftp连接的时候要打开  vi /usr/sbin/stupid-ftpd.conf 修改端口,修改完端口,登入的时候root的密码跟以前不一样,可以从st ...