#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. 第十六章 PHP 操作MySQL

    学习要点:1.PHP 连接到MySQL2.增删改查3.其他常用函数 如果你已经具有了使用PHP.SQL 和MySQL 的丰富经验,现在就可以把所有这些技术组合在一起.PHP 与MySQL 之间稳固的集 ...

  2. Servlet 编程 简单流程处理(重定向)

    流程(来自jiekexueyuan) servlet sucess.jsp error.asp同理 运行结果:

  3. java 处理xml格式数据

    1.单个xml文件 package lia.meetlucene; import java.io.*; import javax.xml.parsers.DocumentBuilder; import ...

  4. sonarqube  安装配置

    http:// www.sonarqube.org MySQL Unsupported mysql version: 5.5. Minimal supported version is 5.6. Th ...

  5. 安装CentOS

    1. 用UltraISO,将CentOS写入U盘,然后将两个CentOS iso文件也拷贝到u盘中,由于u盘FAT32的限制,需要调整第一个iso文件的尺寸,剪切到4GB以内即可拷贝进u盘 2. 用u ...

  6. Web 软件测试 Checklist 应用系列,第 1 部分: 数据输入

    Web 软件测试 Checklist 应用系列,第 1 部分: 数据输入 本文为系列文章"Web 软件测试 Checklist 应用系列"中的第一篇.该系列文章旨在阐述 Check ...

  7. A20板子上的触摸屏设备号变化后解决

  8. Universal Serial Bus USB 3.0

    Computer Systems A Programmer's Perspective Second Edition A Universal Serial Bus (USB) controller i ...

  9. 不要让mysql犹豫不决

    DROP TABLE IF EXISTS `w1`; CREATE TABLE `w1` ( `waid` ) NOT NULL AUTO_INCREMENT, `wa1` ) COLLATE utf ...

  10. Delphi指针及其它(转)

    一.指针:指向一个内存地址的变量或参数. 二.定义指针的方式如下: P: Pointer; //定义了可以指向任何类型的指针,Pointer 为无类型指针: Q, R: ^TType; //定义了指向 ...