zoukankan      html  css  js  c++  java
  • 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;

    }

    }

  • 相关阅读:
    ROW_NUMBER()用法(转)
    winform MD5值生成
    VC使用“添加方法向导”添加调度映射方法“
    MyGeneration配置说明
    dataGridView取消自动生成列
    PHP魔术常量(magic constant)
    Eclipse添加DTD文件实现xml的自动提示功能
    Google:5个常见的SEO错误和6个SEO好主意
    PHP检查PEAR是否工作
    手把手教你在ubuntu上安装LAMP
  • 原文地址:https://www.cnblogs.com/guochen/p/5405001.html
Copyright © 2011-2022 走看看