zoukankan      html  css  js  c++  java
  • POJ 1035

    #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;
    }

    关注我的公众号,当然,如果你对Java, Scala, Python等技术经验,以及编程日记,感兴趣的话。 

    技术网站地址: vmfor.com

  • 相关阅读:
    POJ 1703 Find them, Catch them
    POJ 2236 Wireless Network
    POJ 2010 Moo University
    POJ 2184 Cow Exhibition
    POJ 3280 Cheapest Palindrome
    POJ 3009 Curling 2.0
    POJ 3669 Meteor Shower
    POJ 2718 Smallest Difference
    POJ 3187 Backward Digit Sums
    POJ 3050 Hopscotch
  • 原文地址:https://www.cnblogs.com/gavinsp/p/4563225.html
Copyright © 2011-2022 走看看