Artifact 053f4255282269322f67482123f7fd8d9c056208
#include <vector>
#include <string>
using namespace std;
struct BinaryCode
{
vector<string> decode( string message )
{
vector<string> ans;
ans.push_back( decode(0, message) );
ans.push_back( decode(1, message) );
return ans;
}
string decode(int c, string Q)
{
string P; P += char('0'+c);
for(int i=0; i<Q.size()-1; ++i)
if( '0' <= Q[i]-c && Q[i]-c<='1' )
P += char(Q[i]-c),
c = P[P.size()-2]-'0' + P[P.size()-1]-'0';
else
return "NONE";
return c==Q[Q.size()-1]-'0' ? P : "NONE";
}
};