#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. 李洪强-C语言关键字、标识符和注释

    一.关键字 C语言提供的有特殊含义的符号,共32个. 在Xcode中关键字全部高亮显示,关键字全部都为小写.如return.int等. 二.标识符 定义:标识符是程序员在程序中自定义的一些符号和名称. ...

  2. WebUI-自用

    一.常用插件 1.弹出框架: http://layer.layui.com/ http://layer.layui.com/mobile/ 移动端 http://aui.github.io/artDi ...

  3. MS14-025引起的问题 - 2

    5月,微软在13日发布月度安全更新,其中 有KB2871997和 KB2928120两个知识库文章Knowledgeased(而KB2871997甚至不是Security Bulletin).对于无论 ...

  4. 用Get-ADComputer取非常用属性的值

    由于GE使用的是Windows2003+Powershell2.0, 所以某些命令无法使用,比如想取lastLogon和lastLogonTimestamp这两个属性,在Powershell3.0下可 ...

  5. 分布式缓存(Cache)

    1. 单层分布式cache. 如memcache. 2. 多层分布式cache. 服务端和调用者本地都存放cache, 使用udp组播解决cache同步更新问题,但不可靠. 3. 改进的多层分布式ca ...

  6. Nginx 报错: nginx: [error] open() "/usr/local/nginx/logs/nginx.pid" failed (2: No such file or directory) 的解决方法

    今天测试域名访问不了,登陆 Linux(Ubuntu)重启Nginx: nginx -s reload 结果报错: nginx: [error] open() : No such file or di ...

  7. ios_常用关键字

    一.关键字说明 1. @synthesize关键字:  根据@property设置,自动生成成员变量相应的存取方法,从而可以使用点操作符来方便的存取该成员变量 . 2. @implementation ...

  8. [转]通过Mesos、Docker和Go,使用300行代码创建一个分布式系统

    http://www.csdn.net/article/2015-07-31/2825348 [编者按]时下,对于大部分IT玩家来说,Docker和Mesos都是熟悉和陌生的:熟悉在于这两个词无疑已成 ...

  9. ease of rerouting traffic in IP networks without readdressing every host

    https://en.wikipedia.org/wiki/Network_address_translation In the face of the foreseeable global IP a ...

  10. 将所有程序设置XML集中到一个单独XML配置文件的方法:使用appSettings元素的configSource元素

    在.NET程序中,程序的配置文件默认都会放在程序根目录下的web.config(网站程序)或App.config(控制台等程序),在该配置文件中可以定义若干程序配置信息. 在此以网站程序为例,首先将下 ...