#include <vector> #include <list> #include <map> #include <set> #include <deque> #include <stack> #include <bitset> #include <algorithm> #include <functional> #include <numeric> #include <utility> #include <sstream> #include <iostream> #include <iomanip> #include <cstdio> #include <cmath> #include <cstdlib> #include <ctime> using namespace std; class BinaryCode { public: vector <string> decode(string); }; int get_int(char x) { return x-'0'; } string get_string(string message,char assump) { string first; int s = message.size(); first.push_back(assump); first.push_back(get_int(message[0]) - get_int(assump) + '0'); for(int i=1;i<s-1;++i) { if(first[i] < '0' || first[i] >'3') { first.clear(); first = "NONE"; break; } else { char v = get_int(message[i]) - (get_int(first[i-1]) + get_int(first[i])) +'0'; first.push_back(v); } } if(s>1) if(message[s-1] != (get_int(first[s-1])+get_int(first[s-2]) + '0')) return "NONE"; return first; } vector<string> BinaryCode::decode(string message) { string first=""; string None[2] = {"NONE","NONE"}; int s = message.size(); if(s ==0 || message[0] >'2' || message[s-1] > '2') { vector<string> v(None,None+2); //v.push_back("NONE"); //v.push_back("NONE"); return v; } vector<string> v; v.push_back(get_string(message,'0')); v.push_back(get_string(message,'1')); return v; } //<%:testing-code%> //Powered by [KawigiEdit] 2.0! int main() { BinaryCode b; vector<string> x = b.decode("3"); cout<<x[0]<<" "<<x[1]<<endl; }
Friday, August 3, 2012
TOPCODER SRM 144 Div 1
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment