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