TCHS SRM 53 250 pt - DNAConstruction editorial: http://community.topcoder.com/tc?module=Static&d1=hs&d2=match_editorials&d3=hs_srm53
TCHS SRM 53 250 pt - DNAConstruction solution:
#include <iostream> #include <cstring> #include <algorithm> class DNAConstruction { public: int maxLength(std::string n) { int a=0, t=0, c=0, g=0, tot=0; for(int i=0; i<n.length(); i++) { if(n[i]=='A') a++; else if(n[i]=='T') t++; else if(n[i]=='C') c++; else if(n[i]=='G') g++; } tot=std::min(a, t) + std::min(c, g); return tot; } };
for proper use of "min" and "max" in c++:
1 - http://www.cplusplus.com/reference/algorithm/max/
2 - http://stackoverflow.com/questions/1632145/use-of-min-and-max-functions-in-c
and for iterating through string in c++: http://stackoverflow.com/questions/1315041/how-can-i-iterate-through-a-string-and-also-know-the-index-current-position
No comments:
Post a Comment