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

    }

    }

  • 相关阅读:
    [PoC]某B2B网站的一个反射型XSS漏洞
    Python中的基本语句
    视频: 千重浪Linux系统调试技术培训 03-01_Basic-CPU-Register
    POJ 2955 Brackets (区间dp 括号匹配)
    LeetCode 146 LRU Cache
    Poj1734题解
    Python
    小胖说事29-----iOS中Navigation中左滑pop页面的三种方法
    深入理解javascript之原型
    android 弹幕评论效果
  • 原文地址:https://www.cnblogs.com/guochen/p/5405001.html
Copyright © 2020-2023  润新知