Wednesday, June 25, 2014

TopCoder High School SRM 14 Level one - 250 pt - Xox solution

TopCoder High School SRM 14 Level one - 250 pt - Xox statement: http://community.topcoder.com/stat?c=problem_statement&pm=6720&rd=10066

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

TopCoder High School SRM 14 Level one - 250 pt - Xox solution: 

#include <iostream>
using namespace std;

class Xox {
    public: int count(string s) {
        int cnt=0, b[55]={0};
        for(int i=2; i<s.length(); i++) {
            if(b[i-2]==1 && s[i-1]=='o' && s[i]=='x') cnt+=2, b[i]=1;
            else if(s[i-2]=='x' && s[i-1]=='o' && s[i]=='x') cnt+=3, b[i]=1;
        }
        return cnt;
    }
};

No comments:

Post a Comment