POJ 1035 Spell checker 字符串暴力

看好题目要求做就行  没什么难的 虽然wa了一上午,找了半天bug没有找出来,然后晚上回宿舍重新敲了一遍接着ac'了~~~~Orz

#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>

using namespace std;

char s[11100][20];
char re[11100][20];
int e, g;

bool cor(int x)
{
    for(int i = 1;i <= e;i++){
        if(!strcmp(s[i],re[x])){
            return true;
        }
    }
    return false;
}
bool view(char s[], char a[])
{
    int i;
    int cnt = 0;
    for(i = 0;s[i];i++){
        if(s[i] != a[i]){
            cnt++;
        }
    }
    if(cnt == 1){
        return true;
    }else {
        return false;
    }
}
bool del(char s[], char a[])
{
    int i, j;
    int cnt = 0;
    i = 0;
    j = 0;
    for(;s[i];){
        if(s[i] == a[j]){
            i++;
            j++;
        }else {
            cnt++;
            i++;
        }
    }
    if(cnt == 1){
        return true;
    }else {
        return false;
    }
}
int main()
{
    int i;
    char a[20];
    e = 0;
    while(1){
        scanf("%s", a);
        if(!strcmp(a,"#")){
            break;
        }else{
            strcpy(s[++e],a);
        }
    }
    g = 0;
    while(1){
        scanf("%s", a);
        if(!strcmp(a,"#")){
            break;
        }else {
            strcpy(re[++g],a);
        }
    }
    for(i = 1;i <= g;i++){
        if(cor(i)){
            printf("%s is correct\n", re[i]);
            continue;
        }
        printf("%s:", re[i]);
        for(int j = 1;j <= e;j++){
            int lens = strlen(s[j]);
            int lenre = strlen(re[i]);
            if(lens - lenre == 1){
                if(del(s[j],re[i])){
                    printf(" %s", s[j]);
                }
            }else if(lenre - lens == 1){
                if(del(re[i],s[j])){
                    printf(" %s", s[j]);
                }
            }else if(lenre == lens){
                if(view(re[i],s[j])){
                    printf(" %s", s[j]);
                }
            }
        }
        printf("\n");
    }

    return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值