• 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;

    }

    }

  • 相关阅读:
    Sql in VBA 之 初识ADO
    Excel读取Word Table元素
    工作表是否已存在函数
    按模板生成工作表
    多层字典对象应用案例分析
    字典的应用
    字典的基本功能
    Dictionary 对象
    File System Object(FSO对象)B
    File System Object(FSO对象)A
  • 原文地址:https://www.cnblogs.com/guochen/p/5405001.html
Copyright © 2020-2023  润新知