#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. Struts2 中result type属性说明

    Struts2 中result type属性说明 首先看一下在struts-default.xml中对于result-type的定义: <result-types><result-t ...

  2. C/C++ 位运算符

    C/C++位操作运算符 操作符 功能 用法 ~ 位求反 ~expr << 左移 expr1 << expr2 >> 右移 expr1 >> expr2 ...

  3. 几个与时间相关的php的函数

    这些函数很常用,但是不用的话,像我这样的初学者放下就记不清了,这时最好的办法就是去查文档,写一下印象会更深一些 1.时间戳函数strtotime():一个就是string to time(我自己这样理 ...

  4. 戴尔PowerEdge服务器命名规则和型号分类

    从第十代服务器开始,戴尔重新规范了服务器的名字,以现在的第十二代主流PowerEdge R620服务器为例: 第一位是字母,R代表机架式服务器,其它有: R:Rack,机架式服务器 T:Tower,塔 ...

  5. Jquery&JS简单选项卡

    结果,如图 为了明显,用绿色+红色 第一步:静态布局 先写html代码和css样式 要点一:  ul li都为块级元素,可以用height,但是里面字体不居中,我们用line-height,即达到居中 ...

  6. 【转】Html页面结构范例

    原文地址:http://www.51testing.com/html/38/225738-220986.html · HTML · HEAD · LINK ... CSS files required ...

  7. twitter storm源码走读之8 -- TridentTopology创建过程详解

    欢迎转载,转载请注明出处,徽沪一郎. 从用户层面来看TridentTopology,有两个重要的概念一是Stream,另一个是作用于Stream上的各种Operation.在实现层面来看,无论是str ...

  8. 《你不知道的JavaScript》读书笔记(二)词法作用域

    JavaScript 采用的是 词法作用域 的工作模型. 定义 词法化:大部分标准语言编译器的第一个工作阶段叫词法化(单词化),这个过程会对源代码中的字符进行检查,如果是有状态的解析过程,还会赋予单词 ...

  9. ThinkPHP 学习笔记 ( 五 ) 数据验证

    根据官网的教程 ( http://www.thinkphp.cn/info/171.html ),数据验证的使用静态定义方式 ( 以 regex 为例 ) 无法验证数据: 而采用动态验证则正常: 控制 ...

  10. 一些站点使用的服务器软件、js 框架大收集 [ 整理中 ]

    Chrome 的扩展应用 ChromeSnifferPlus ( 开源中国地址:http://www.oschina.net/p/chromesnifferplus,GitHub 地址:https:/ ...