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 )

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值