TopCoder High School SRM 27 Level one - 250 pt - Brick Mystery editorial: http://community.topcoder.com/tc?module=Static&d1=hs&d2=match_editorials&d3=hs_srm27
TopCoder High School SRM 27 Level one - 250 pt - Brick Mystery solution:
#include <iostream> #include <vector> #include <algorithm> using namespace std; class BrickMystery { public: vector <string> createPattern(string m) { vector <string> a; a.push_back("x.......x"); for(int i=0; i<m.length(); i++) { string b=""; for(int j=0; j<7; j++) { if((m[i]>>j)&1) b+='x'; else b+='.'; } reverse(b.begin(), b.end()); a.push_back('x'+b+'x'); } a.push_back("x.......x"); return a; } };
note: to learn about conversion of decimal numbers to binary numbers: http://garakchy.blogspot.com.tr/2014/06/a-tutorial-on-binary-numbers-conversion.html
reverse() string is of <algorithm> c++ : http://stackoverflow.com/a/198210/2948746
No comments:
Post a Comment