Saturday, December 13, 2014

TCHS SRM 56 250 pt - Strange Comparator solution

TCHS SRM 56 250 pt - Strange Comparator: http://community.topcoder.com/stat?c=problem_statement&pm=10010&rd=13525

TCHS SRM 56 250 pt - Strange Comparator editorial:  http://community.topcoder.com/tc?module=Static&d1=hs&d2=match_editorials&d3=hs_srm56

TCHS SRM 56 250 pt - Strange Comparator solution:


#include <iostream>
#include <vector>

class StrangeComparator {
 public: std::vector <std::string> compareString(std::vector <std::string> a, std::vector <std::string> b) {
  int cnt=0, f=0;
  std::vector <std::string> v;
  for(int i=0; i<a.size(); i++, cnt=0, f=0) {
   if(a[i].length()!=b[i].length()) f=1;
   if(f==0) for(int j=0; j<a[i].length(); j++) if(a[i][j]!=b[i][j]) cnt++;   
   if(cnt>1 || f==1) v.push_back("No");
   else v.push_back("Yes");
  }
  return v;
 }
};



No comments:

Post a Comment