utsubo’s blog

競技プログラミングとか.

SRM654 Div2 Easy / SquareScoresDiv2

問題

http://community.topcoder.com/stat?c=problem_statement&pm=13700
ある文字列の部分文字列の中で同じ文字が連続しているものをカウントする。

解法

全探索

class SquareScoresDiv2 {
	public: int getscore(string s) {
		int ret = 0;
		for(int i=0;i<s.size();i++){
			for(int j=i;j<s.size();j++){
				if(s[i] == s[j])ret++;
				else break;
			}
		}
		return ret;
	}

};