View Code of Problem 105

#include<stdio.h>
#include<string.h>

int main(){
    int len,len1,i,j,k,m,flag;
	char str[3000],s[3000],c;

	while(scanf("%s",&str)&&(strcmp(str,"END")!=0))
	{
		len=strlen(str);
		scanf("%d",&m);
		for(i=0;i<m;i++)
		{
			scanf("%s",&s);
			len1=strlen(s);
			if(len1<len)
			{
				for(k=j=0;j<len1;j++)
				{
					if (str[j]!=s[j])
					{
						k=j+1;
						c=str[j];
						break;
					}
					if(k==0)
					{
						k=len;
						c=str[j];
					}
				}
				printf("%d %d insert %c\n",i+1,k,c);
			}
			else if(len1>len)
			{
				for(k=j=0;j<len-1;j++)
				{
					if (str[j+1]!=s[j+1] && s[j]==s[j+1])
					{
						k=j+1;
						c=s[j];
						break;
					}
					if (k==0)
					{
						k=len;
						c=str[len-1];
					}
				}
				printf("%d %d delete %c\n",i+1,k,c);
			}
			else
			{
				for(k=j=0;j<len;j++)
				{
					if (str[j]!=s[j])
					{
						k=j+1;
						c=str[j];
						flag=0;
						break;
						
					}
					if (k==0)
					{
						k=len;
						c=str[len-1];
						flag=1;
					}
				}
				if(flag==0)
	             	printf("%d %d change %c\n",i+1,k,c);
				else 
					printf("%d OK!\n",i+1);
			}
		}
	}
	return 0;
}

Double click to view unformatted code.


Back to problem 105