Friday, December 12, 2014

TCHS SRM 51 250 pt - Missing Digits solution

TCHS SRM 51 250 pt - Missing Digits: http://community.topcoder.com/stat?c=problem_statement&pm=7920&rd=13484

TCHS SRM 51 250 pt - Missing Digits editorial:  http://community.topcoder.com/tc?module=Static&d1=hs&d2=match_editorials&d3=hs_srm51

TCHS SRM 51 250 pt - Missing Digits solution:


#include <iostream>
#include <sstream>
#include <vector>

class MissingDigits {
 public: std::string isAllowed(std::vector <int> na, int r) {
  std::ostringstream ss;
  std::string s1, s2;
  ss<<r, s1=ss.str();
  for(int i=0; i<na.size(); i++) {
   std::ostringstream ss2;
   ss2<<i<<na[i], s2=ss2.str();
   if(s1.find(s2)!=std::string::npos) return "NO";
  }  
 return "YES";
 }
};
 
 
for "ostringstream" or to convert int to string in C++, see:  
http://stackoverflow.com/questions/5590381/easiest-way-to-convert-int-to-string-in-c
 
 
and for "find" substring in a string in C++, see: 
http://www.cplusplus.com/reference/string/string/find/

No comments:

Post a Comment