Monday, July 7, 2014

Topcoder High School SRM 35 Level one - 250 pt - Names List solution

Topcoder High School SRM 35 Level one - 250 pt - Names List statement: http://community.topcoder.com/stat?c=problem_statement&pm=8037&rd=10771

Topcoder High School SRM 35 Level one - 250 pt - Names List editorial: http://community.topcoder.com/tc?module=Static&d1=hs&d2=match_editorials&d3=hs_srm35

Topcoder High School SRM 35 Level one - 250 pt - Names List solution: 


#include <iostream>
#include <vector>

class NamesList {
    public: std::string popularInitial(std::vector <std::string> n, int k) {
        int a[30]={0}, idx=0, ma=0;
        std::string s;
        for(int i=0; i<n.size(); i++) if(n[i].length()>=k) a[n[i][k-1]-'A']++;
        for(int i=29; i>=0; i--) if(a[i]>=ma) ma=a[i], idx=i;
        s=idx+'A';
        return s;
    }
};

No comments:

Post a Comment