-
Notifications
You must be signed in to change notification settings - Fork 0
/
1_5.cpp
60 lines (53 loc) · 1007 Bytes
/
1_5.cpp
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
56
57
58
59
60
#include <iostream>
#include <string>
using namespace std;
bool oneAway(std::string wrd1, std::string wrd2)
{
std::string longer, shorter;
if (wrd1.length() >= wrd2.length())
{
longer = wrd1;
shorter = wrd2;
}
else
{
longer = wrd2;
shorter = wrd1;
}
if (longer.length() - shorter.length() > 1)
{
return false;
}
int poss = 0;
int posl = 0;
bool diff = false;
while (poss < shorter.length())
{
if (longer[posl] != shorter[poss])
{
if (diff)
{
return false;
}
diff = true;
posl++;
if (longer.length() == shorter.length())
{
poss++;
}
}
else
{
posl++;
poss++;
}
}
return true;
}
int main(int argc, char* argv[])
{
if (oneAway("pale","bake"))
{
std::cout << "yes";
}
}