Monday, June 30, 2014

TopCoder High School SRM 28 Level one - 250 pt - Swapping Marbles solution

TopCoder High School SRM 28 Level one - 250 pt - Swapping Marbles statement: http://community.topcoder.com/stat?c=problem_statement&pm=6882&rd=10652

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

TopCoder High School SRM 28 Level one - 250 pt - Swapping Marbles solution: 


#include <iostream>
using namespace std; 

class SwappingMarbles {
    public: int swaptions(string c1, string c2) {
        int cnt=0;
        for(int i=1; i<c1.length()-1; i++) {
            for(int j=1; j<c2.length()-1; j++) {
                if(c1[i-1]==c1[i+1] && c1[i-1]==c2[j] && c1[i]!=c2[j] && c2[j-1]==c2[j+1] && c2[j-1]==c1[i]) cnt++;
            }
        }
        return cnt;
    }
};

No comments:

Post a Comment