View Code of Problem 105

#include<stdio.h>
#include<string.h>
int main(){
	char word[2222];
	while(scanf("%s",word)!=EOF){
		if(strcmp(word,"END")==0)break;
		int n,len,p=1;
		len =strlen(word);
		scanf("%d",&n);
		while(p<=n){
			char str[2222];
			scanf("%s",str);
			int l  =strlen(str);
			if(strcmp(str,word)==0){
				printf("%d OK!\n",p);	
			}
			else if(l==len){
				for(int i=len-1;i>=0;i--){
					if(word[i]!=str[i]){
						printf("%d %d change %c\n",p,i+1,word[i]);
						break;
					}
				}
			}else if(l>len){
				int i=l,j=len,flag=0;
				while(i>=0&&j>=0){
					if(word[j]!=str[i]){
						printf("%d %d delete %c\n",p,i+1,str[i]);
						flag=1;
						break;
					}
					i--;
					j--;
				}
				if(flag==0)printf("%d %d delete %c\n",p,1,str[i]);
			}else{
				int i=l,j=len,flag=0;
				while(i>=0&&j>=0){
					if(word[j]!=str[i]){
						printf("%d %d insert %c\n",p,j+1,word[j]);
						flag=1;
						break;
					}
					i--;
					j--;
				}
				if(flag==0)printf("%d %d insert %c\n",p,1,word[j]);
			}
			p++;
		}
	
	}
	return 0;

} 

Double click to view unformatted code.


Back to problem 105