• poj1035


    简单题

    View Code
    #include <iostream>
    #include <string>
    #include <cmath>
    using namespace std;
    
    const    int        maxn = 10001;
    
    string    dictionary[maxn], checking;
    int        total;
    
    bool common(string a, string b)
    {
        int        i, different;
        string    t;
        bool    first;
    
        if (abs(int(a.length() - b.length())) > 1)
            return false;
        if (a.length() == b.length())
        {
            different = 0;
            for (i = 0; i < a.length(); i++)
                if (a[i] != b[i])
                    different++;
            if (different > 1)
                return false;
            return true;
        }
        if (a.length() > b.length())
        {
            t = a;
            a = b;
            b = t;
        }
        first = true;
        i = 0;
        while (i < a.length())
        {
            if (a[i] != b[i])
            {
                if (first)
                    b.erase(i, 1);
                else
                    return false;
                first = false;
            }
            else
                i++;
        }
        return true;
    }
    
    int main()
    {
        int        i;
        bool    correct;
    
        //freopen("t.txt", "r", stdin);
        i = 0;
        while (true)
        {
            getline(cin, dictionary[i]);
            if (dictionary[i] == "#")
                break;
            i++;
        }
        total = i;
        while (true)
        {
            getline(cin, checking);
            if (checking == "#")
                break;
            cout << checking;
            correct = false;
            for (i = 0; i < total; i++)
                if (checking == dictionary[i])
                {
                    cout << " is correct";
                    correct = true;
                    break;
                }
            if (!correct)
            {
                cout << ":";
                for (i = 0; i < total; i++)
                    if (common(checking, dictionary[i]))
                    {
                        cout << " ";
                        cout << dictionary[i];
                    }
            }
            cout << endl;
        }
        return 0;
    }
  • 相关阅读:
    innodb buffer pool小解
    information_schema系列十一
    Shader编程教程
    第四章 继承
    第三章 对象和类型
    第二章:核心C#
    前言和第一章.NET的体系结构
    单例模式
    代理模式
    第 1 章 策略模式【Strategy Pattern】
  • 原文地址:https://www.cnblogs.com/rainydays/p/2824048.html
Copyright © 2020-2023  润新知