CPP
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
#include <iostream>
#include <string>
bool strStuff(std::string x, std::string y)
{
int a=0, d; bool t;
while (++a < x.length()) {
t=0; d=y.find(std::string(1, x[a]));
while (d != std::string::npos) {
t|=(y[d+1]==x[a-1]||y[d-1]==x[a-1]);
d=y.find(std::string(1, x[a]), d+1);
}
if (!t) return 0;
}
return 1;
}
int main ()
{
std::cout << strStuff("kayaks", "skay");
std::cout << strStuff("bit", "bite");
std::cout << strStuff("atatata", "ta");
std::cout << strStuff("code", "coddle");
std::cout << strStuff("trirtotrtopip", "tptirtopit");
std::cout << strStuff("abcbcbab", "abcba...cba");
}
Enter to Rename, Shift+Enter to Preview
OUTPUT
Run