bool check(string& a, string& b, string& c) int cal(int n)//算排列 int main() { vector<string> str = { "AAA","AAB","AAC","ABA","ABB","ABC","ACA","ACB","ACC", };//全排列27个 vector<vector<vector<string>>> str_is; for (int i = 0; i < 25; i++) { for (int j = i + 1; j < 27; j++) { for (int k = j + 1; k < 27; k++) { if (check(str[i],str[j],str[k])) { vector<string> tmp2; vector<vector<string>> tmp1; tmp2.push_back(str[i]); tmp2.push_back(str[j]); tmp2.push_back(str[k]); tmp1.push_back(tmp2); str_is.push_back(tmp1); } } } } unordered_map<string, int> hash; int n,res = 0; cin >> n; while (n--) { int m = 3; string tmp; while (m--) { char input; cin >> input; tmp += input; } hash[tmp] ++; } for (auto var : str_is) { int res_tmp ; res_tmp = hash[var[0][0]] * hash[var[0][1]] * hash[var[0][2]]; res += res_tmp; } for (auto var : hash) { if (var.second > 3) res += cal(var.second); }