码迷,mamicode.com
首页 > 其他好文 > 详细

POJ 1035

时间:2015-06-09 16:39:57      阅读:85      评论:0      收藏:0      [点我收藏+]

标签:

#include<iostream>
#include<stdio.h>
#define MAXN 10001
using namespace std;

char dict[MAXN][20];
char s[20];
bool is_replace(const char * a,const char * b);
bool is_delete(const char * a,const char * b);
bool is_add(const char * a,const char * b);
int main()
{
    //freopen("acm.acm","r",stdin);
    int i = 0;
    int j = 0;
    while(cin>>dict[i],dict[i][0] != ‘#‘)
    {
        ++ i;
    }
    while(cin>>s,s[0] != ‘#‘)
    {
        for(j = 0; j < i; ++ j)
        {
            if(strcmp(s,dict[j]) == 0)
            {
                cout<<s<<" is correct"<<endl;
                break;
            }
        }
        if(j == i)
        {
            cout<<s<<": ";
            for(j = 0; j < i; ++ j)
            {
                if(is_replace(s,dict[j]) || is_add(s,dict[j]) || is_delete(s,dict[j]))
                {
                    cout<<dict[j]<<" ";
                }
            }
            cout<<endl;
        }
        else
        {
            continue;
        }
    }
}

bool is_replace(const char * a,const char * b)
{
    int len_a = strlen(a);
    int len_b = strlen(b);
    int i;
    int j;
    int count = 0;
    if(len_a == len_b)
    {
        for(i = 0,j = 0; i < len_a;)
        {
            if(a[i] == b[j])
            {
                ++ i;
                ++ j;
            }
            else
            {
                ++ i;
                ++ j;
                ++ count;
            }
            if(count > 1)
                return false;
        }
    }
    else
    {
        return false;
    }
    return true;
}

bool is_delete(const char * a,const char * b)
{
    int len_a = strlen(a);
    int len_b = strlen(b);
    int i;
    int j;
    int count = 0;
    if(len_a + 1 == len_b)
    {
        for(i = 0,j = 0; j < len_b;)
        {
            if(a[i] == b[j])
            {
                ++ i;
                ++ j;
            }
            else
            {
                ++ j;
                ++ count;
            }
            if(count > 1)
            {
                return false;
            }
        }
    }
    else
    {
        return false;
    }
    return true;
}

bool is_add(const char * a,const char * b)
{
    int len_a = strlen(a);
    int len_b = strlen(b);
    int i;
    int j;
    int count = 0;
    if(len_a == len_b + 1)
    {
        for(i = 0,j = 0; i < len_a;)
        {
            if(a[i] == b[j])
            {
                ++ i;
                ++ j;
            }
            else
            {
                ++ i;
                ++ count;
            }
            if(count > 1)
            {
                return false;
            }
        }
    }
    else
    {
        return false;
    }
    return true;
}

POJ 1035

标签:

原文地址:http://www.cnblogs.com/gavinsp/p/4563225.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!