本文共 960 字,大约阅读时间需要 3 分钟。
1 #include 2 #include 3 typedef unsigned long long ullong; 4 using std::string; 5 6 ullong factorial(ullong i) { 7 if (i > 1) { 8 return i * factorial(i - 1); 9 }10 if (i == 1) {11 return 1;12 }13 if (i == 0) {14 return 0;15 }16 }17 18 ullong count(const string &s) {19 using std::map;20 map repeat_nums;21 for (ullong i = 0; i < s.length(); i++) {22 repeat_nums[s[i]]++;23 }24 ullong result = factorial(s.length());25 for (auto it = repeat_nums.begin(); it != repeat_nums.end(); it++) {26 if (it->second > 1) {27 result /= factorial(it->second);28 }29 }30 return result;31 }32 33 int main() {34 std::cout << count("ABA") << std::endl;35 std::cout << count("ABCDEFGHHA") << std::endl;36 std::cout << count("AABBCC") << std::endl;37 }
转载于:https://www.cnblogs.com/ren-yu/p/11147146.html