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 <algorithm>
#include <iostream>
#include <sstream>
#include <string>
#include <bitset>
#include <cmath>
bool strStuff(std::string x, std::string y)
{
std::stringstream r; int v=0,d=y.find(x[0]),c=d;
for (int i=0; i<x.length()-1; v+=pow(2,i++));
while (d!=std::string::npos)
{
for (int i=0; i<=v; i++,c=d)
{
std::string s, t = std::string(1,y[c]);
r<<std::bitset<64>(i); r>>s; r.clear();
std::reverse(s.begin(), s.end());
s.resize(x.length()-1);
for (int j=0; j<s.length(); t+=y[c],j++)
{
c = s[j]=='1'?c+1:c-1;
if (c<0||c>y.length()-1||x[j+1]!=y[c]) break;
}
if (t==x) return 1;
}
Enter to Rename, Shift+Enter to Preview
OUTPUT
Run