-
Notifications
You must be signed in to change notification settings - Fork 153
/
oneEditAway.c
55 lines (43 loc) · 957 Bytes
/
oneEditAway.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
/* *
* @author : ashwek
* @date : 29/12/2018
*/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int oneEditAway(char Str1[], char Str2[]){
int l1 = strlen(Str1), l2 = strlen(Str2);
int i=0, j=0, diff=0;
if( abs(l1 - l2) > 1 )
return 0;
while( diff<2 && (i < l1) && (j < l2) ){
if( Str1[i] == Str2[j] ){
i++;
j++;
}
else{
diff++;
if( l1 == l2 ){
i++;
j++;
}
else if( l1 < l2 )
j++;
else
i++;
}
}
return diff < 2;
}
void main(){
char Str1[20];
char Str2[20];
printf("Enter string 1 = ");
scanf("%s", Str1);
printf("Enter string 2 = ");
scanf("%s", Str2);
printf("%s & %s are ", Str1, Str2);
if( oneEditAway(Str1, Str2) == 0 )
printf("NOT ");
printf("one edit away\n");
}