Determine whether the two characters ectopic

Ectopic determine whether the two characters? For example, abcdef and badcfe, or abcde and badce.

Procedures are as follows:

#include<stdio.h>
#include<string.h>
void judge(char* arr1,char* arr2,int length1,int length2);
int main()
{
	char arr1[20];
	char arr2[20];
	int length1,length2;
	scanf("%s",arr1);
	scanf("%s",arr2);
	length1=strlen(arr1);
	length2=strlen(arr2);
	judge(arr1,arr2,length1,length2);
}
void judge(char* arr1,char* arr2,int length1,int length2)
{
	int i,j;
	if(arr1==NULL && arr2==NULL)
	{
		printf("Yes!");
		return ;
	}
	if(length1<1 || length2<1 || (length1!=length2))
	{
		printf("No!");
		return ;
	}
	for(i=0,j=1;i<length1,j<length2;)
	{
		if(i==length1-1 && arr1[i]!=arr2[i])
		{
			printf("No!");
			return ;
		}
		if(arr1[i]!=arr2[i+1] || arr1[j]!=arr2[j-1])
		{
			printf("No!");
			return ;
		}
		i=i+2;
		j=j+2;	
	}
	printf("Yes!");
}

 

Published 33 original articles · won praise 30 · views 20000 +

Guess you like

Origin blog.csdn.net/baidu_15547923/article/details/99830930