zoukankan      html  css  js  c++  java
  • poj1035

    题目意思很简单,给定几个字符串,若在词典中有相匹配,输出correct

    如果与词典中的词差距一个字符,可以通过添加,删除,修改变为正确,那么输出

    没有就不输出

    解法:水题,暴力就可以,注意易错部分的匹配

    代码可能比较难理解

    #include<stdio.h>
    #include<string.h>
    char s[10010][20];
    int n,m,len[10010];
    bool right(char c[30]){
    	for(int i=0;i<n;++i) if(!strcmp(c,s[i])) return 1;
    	return 0;
    }
    inline int abs(int a){   
        return (a^(a>>31))-(a>>31);
    }  
    bool ok(char* a,char* b){
    	int l1=strlen(a);
    	int l2=strlen(b);
    	if(l1>l2){ 
    		l1+=l2;l2=l1-l2;l1-=l2;
    		char* c=a;a=b;b=c;
    	}
    	if(l1==l2) {
    		bool cnt=0;
    		for(int i=0;i<l1;++i)	
    			if(cnt&&a[i]!=b[i])return 0;
    			else cnt|=(a[i]!=b[i]);
    		return 1;
    	}
    	else {
    		bool cnt=0;
    		for(int i=0;i<l2;++i)
    			if(cnt&&a[i-cnt]!=b[i])return 0;
    			else cnt|=(a[i-cnt]!=b[i]);
    		return 1;
    	}
    }
    			
    int main(){
    	scan:
    		scanf("%s",s[n]);
    		len[n]=strlen(s[n]);
    		if(*s[n++]=='#') n--;
    		else goto scan;
    	char c[30]; int l;
    	work:
    		scanf("%s",c);
    		if(*c=='#') goto end;
    		if(right(c)) {
    			printf("%s is correct
    ",c);
    			goto work;
    		}
    		l=strlen(c);
    		printf("%s:",c);
    		for(int i=0;i<n;++i)
    			if(abs(len[i]-l)<2) 
    				if(ok(s[i],c)) printf(" %s",s[i]);
    		puts("");
    		goto work;
    	end: return 0;
    }


  • 相关阅读:
    HDU6168 Numbers
    HDU6170 Two strings
    UVA11426 GCD
    hihocoder1560 H国的身份证号码II
    HDU6156 Palindrome Function
    UVA10917 Walk Through the Forest
    UVA11374 Airport Express
    hihocoder1323 回文字符串
    hihocoder1543 SCI表示法
    CodeForces501C Misha and Forest
  • 原文地址:https://www.cnblogs.com/Extended-Ash/p/9477383.html
Copyright © 2011-2022 走看看