SRM 428 DVI2 500
与えられた文字列の隣同士が異なる場合が何個あるか数えろという問題。
順列組み合わせを自分で書こうとして手間だったけど、早々にあきらめてSTLのAlgorithmを使用すると一瞬で解決。
next_permutationが便利すぎるんじゃ。
#include <string> #include <algorithm> using namespace std; class TheLuckyString{ public: int count(string s) { sort(s.begin(), s.end()); int count = 0; do { bool flag = false; for (int i = 1; i < (int)s.size(); i++){ if (s[i-1] == s[i]){ flag = true; } } if (!flag){ count++; } } while (next_permutation(s.begin(), s.end())); return count; } };