How to determine if two strings are sufficiently close?
Posted
by
A.06
on Stack Overflow
See other posts from Stack Overflow
or by A.06
Published on 2012-10-23T02:32:00Z
Indexed on
2012/10/23
5:04 UTC
Read the original article
Hit count: 93
We say that we can "hop" from the word w1 to the word w2 if they are "sufficiently close". We define w2 to be sufficiently close to w1 if one of the following holds:
w2 is obtained from w1 by deleting one letter.
w2 is obtained from w1 by replacing one of the letters in w1 by some letter that appears to its right in w1 and which is also to its right in alphabetical order.
I have no idea how to check if 2. is fulfilled. To check if 1. is possible this is my function:
bool check1(string w1, string w2){
if(w2.length - w1.length != 1){
return false;
}
for(int i = 0,int j = 0;i < w2.length;i++;j++){
if(w2[i] == w1[j]){//do nothing
}
else if(i == j){
j++;
}
else{
return false;
}
}
return true;
}
Given two words w1 and w2, how do we check if we can 'hop' from w1 to w2?
© Stack Overflow or respective owner