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;

    }

    }

  • 相关阅读:
    图论 —— tarjan 缩点 割点 (学习历程)连载中......
    模拟赛记
    模板(按照洛谷顺序)
    CSP-S退役记
    各知识点运用技巧总结
    P3665 [USACO17OPEN]Switch Grass
    跳跳棋——二分+建模LCA
    P3043 [USACO12JAN]牛联盟Bovine Alliance——并查集
    [ZJOI2013]K大数查询——整体二分
    CF741D Arpa’s letter-marked tree and Mehrdad’s Dokhtar-kosh paths——dsu on tree
  • 原文地址:https://www.cnblogs.com/guochen/p/5405001.html
Copyright © 2011-2022 走看看