20230402网易有道笔试之归元等计算(ac)
#include<iostream>
#include<algorithm>
#include<map>
using namespace std;
string unique_string(string s) {
sort(s.begin(), s.end());
s.erase(unique(s.begin(), s.end()), s.end());
return s;
}
int main() {
string A;
int n;
while (cin >> A >> n) {
int res = 0;
map<string, int> m_s;
for (int i = 0 ; i < n ; ++i) {
string B;
cin >> B;
B = unique_string(B);
if (m_s.find(B) != m_s.end())
m_s[B]++;
else
m_s.insert(pair<string , int>(B , 1));
}
A = unique_string(A);
for(map<string , int>::iterator it = m_s.begin() ; it != m_s.end() ; ++it){
string temp = unique_string(A + it->first);
int b = 0;
if (m_s.find(temp) == m_s.end())
continue;
else
b = m_s[temp];
int a = it->second;
if(temp == it->first)//数量为n * (n - 1)
res += a * (a - 1);
else//数量为n * m
res += a * b;
}
cout<<res<<endl;
}
return 0;
}
欢迎评论区留言!!!
#网易笔试##春招笔试##悬赏#
迅雷公司福利 193人发布
查看25道真题和解析