poj1035

字符串,水题,1A。话说我逃课了额。。

#include <iostream>
#include <string>

using namespace std;

string dic[10005];
string word[55];

bool change(string word, string dic)
{
    int countt = 0;
    for (int i = 0; i < word.length(); i++)
    {
        if (word[i] != dic[i])
        {
            countt++;
            if (countt>1return false;
        }
    }
    return true;
}

bool del(string word, string dic)
{
    int countt = 0;
    int point_of_word = 0
    int point_of_dic = 0;
    for (int i = 0; i < word.length(); i++)
    {
        if (word[point_of_word] != dic[point_of_dic])
        {
            point_of_word++;
            countt++;
            if (countt>1return false;
        }
        else
        {
            point_of_word++;
            point_of_dic++;
        }
    }
    return true;
}

bool add(string word, string dic)
{
    int countt = 0;
    int point_of_word = 0;
    int point_of_dic = 0;
    for (int i = 0; i < dic.length(); i++)
    {
        if (word[point_of_word] != dic[point_of_dic])
        {
            point_of_dic++;
            countt++;
            if (countt>1return false;
        }
        else
        {
            point_of_word++;
            point_of_dic++;
        }
    }
    return true;
}

int main()
{
    memset(dic, 0sizeof(dic));
    memset(word, 0sizeof(word));
    string s;
    int count_of_dics = 0;
    int count_of_words = 0;

    while (cin >> s && s != "#")
    {
        dic[count_of_dics++] = s;
    }
    while (cin >> s && s != "#")
    {
        word[count_of_words++] = s;
    }

    int *address = new int[count_of_dics];
    int p = 0;

    for (int i = 0; i < count_of_words; i++)
    {
        bool flag = false;
        int length = word[i].length();
        memset(address, 0sizeof(address));
        p = 0;
        for (int j = 0; j < count_of_dics; j++)
        {
            if (length == dic[j].length())
            {
                if (word[i] == dic[j])
                {
                    flag = true;
                    break;
                }
                else if (change(word[i], dic[j]))
                {
                    address[p++] = j;
                //    cout << "*******change*******" << endl;
                //    cout << dic[j] << endl;
                }
            }
            else if (length == dic[j].length() + 1)//delete
            {
                if (del(word[i], dic[j]))
                {
                    address[p++] = j;
                //    cout << "******del******" << endl;
                //    cout << dic[j] << endl;
                }
            }
            else if (length == dic[j].length() - 1)//add
            {
                if (add(word[i], dic[j]))
                {
                    address[p++] = j;
                //    cout << "******add******" << endl;
                //    cout << dic[j] << endl;
                }
            }
        }
        if (flag)
        {
            cout << word[i] << " is correct" << endl;
        }
        else
        {
            //cout << p << endl;
            cout << word[i] << ": ";
            for (int k = 0; k < p; k++)
            {
                cout << dic[address[k]] << ' ';
            }
            cout << endl;
        }
    }
    return 0;
}
* This source code was highlighted by YcdoiT. ( style: Oceanblack )

你可能感兴趣的:(数据结构,ACM题解报告)