Friday, August 22, 2014

TC SRM 630 div2 250 pt - Double Letter solution

TC SRM 630 div2 250 pt - Double Letter solution: 


#include <iostream>
#include <string>

class DoubleLetter {
    public: std::string ableToSolve(std::string s) {
        int flag=0, cnt=0;
        while(!flag) {
            for(int i=1; i<s.length(); i++) if(s[i-1]==s[i]) s.erase(i-1, 2);
            cnt++;
            if(!s.length()) flag=1;
            if(s.length()%2 || cnt==100) break;
        }
        if(flag) return "Possible";
        else return "Impossible";
    }
};

No comments:

Post a Comment