题解 | #查找兄弟单词#
查找兄弟单词
https://www.nowcoder.com/practice/03ba8aeeef73400ca7a37a5f3370fe68
#include <iostream>
#include <vector>
#include <cstring>
#include <algorithm>
using namespace std;
int main() {
int len;
cin>>len;
int count = len;
vector<string> dict;
while(count--)
{
string temp;
cin>> temp;
dict.push_back(temp);
}
string target;
cin>>target;
int index;
cin>>index;
vector<int> hashTar(26,0);
vector<string>result;
for(auto i:target)
{
hashTar[i-97] ++;
}
for(int i = 0; i < len; i++)
{
vector<int> hash(26,0);
if(dict[i].size()==target.size())
{
if(dict[i]!=target)
{
for(auto ch:dict[i])
hash[ch-97]++;
bool flag = true;
for(int j = 0; j < 26;j++)
{
if(hashTar[j]!=hash[j])
flag = false;
}
if(flag)
{
result.push_back(dict[i]);
}
}
}
}
sort(result.begin(),result.end());
if(result.size()==0)
cout<<0;
else
cout<<result.size()<<endl<<result[index-1];
}
// 64 位输出请用 printf("%lld")
