Thursday, June 26, 2014

TopCoder High School SRM 21 Level one - 250 pt - Post Office solution

TopCoder High School SRM 21 Level one - 250 pt - Post Office statement: http://community.topcoder.com/stat?c=problem_statement&pm=6794&rd=10073

TopCoder High School SRM 21 Level one - 250 pt - Post Office editorial:
http://community.topcoder.com/tc?module=Static&d1=hs&d2=match_editorials&d3=hs_srm21

TopCoder High School SRM 21 Level one - 250 pt - Post Office solution: 

#include <iostream>
#include <string>
#include <algorithm>
using namespace std;

class PostOffice {
    string get(string s) {
        string r = "";
        for(int i=0; i<s.size(); i++) if(s[i]!=' ') r += tolower(s[i]);
        return r;
    }
    public: int matchAddress(string s1, string s2) {
        string a = get(s1), b = get(s2);
        int ma=max(a.size(), b.size()), idx=-1;
        for(int i=0; i<ma; i++) {
            if(a[i]!=b[i]) { idx=i; break; }
        }
        return idx;
    }
};


No comments:

Post a Comment