class Alliteration { public: int count(vector <string> w) { for(int i=0; i<w.size(); ++i){ string s; for(int j=0; j<w[i].size(); ++j){ s += toupper( w[i][j] ); break; } w[i] = s; } int cnt = 0; for(int i=0; i+1<w.size(); ++i){ if( w[i] != w[i+1] )continue; ++cnt; while(i+1 < w.size() && w[i] == w[i+1] )++i; } return cnt; } };500
class PalindromeDecoding { public: string decode(string code, vector <int> pos, vector <int> len) { const int size = pos.size(); for(int i=0; i<size; ++i){ string s = code.substr( pos[i], len[i] ); reverse( s.begin(), s.end() ); code.insert( pos[i] + len[i], s ); } return code; } };1000
解説を見て解いた。
class ProductBundling { public: int howManyBundles(vector <string> v) { set<string> s; for(int i=0; i<v[0].size(); ++i){ string t; for(int j=0; j<v.size(); ++j){ t += v[j][i]; } s.insert(t); } return s.size(); } };
0 件のコメント :
コメントを投稿