#include <bits/stdc++.h>
using namespace std;
class Person
{
private:
string name;
vector<Person> friends;
int threshold;
vector<char> problems;
public:
Person(){}
void input(int n)
{
cin>>name;
for(int i = 0; i < n; i++)
{
char tem;
cin>>tem;
problems.push_back(tem);
}
cin>>threshold;
}
void output()
{
vector<Person>::iterator iter;
cout<<name<<"'s friends are: ";
if(friends.empty())
cout<<"NONE"<<endl;
else
{
iter = friends.begin();
cout<<iter->name;
for(iter = friends.begin()+1; iter < friends.end(); iter++)
cout<<","<<iter->name;
cout<<endl;
}
}
bool judgeFriends(Person &Aperson)
{
vector<char>::iterator cur,trans;
int common = 0;
for(cur = problems.begin(),trans = Aperson.problems.begin(); cur < problems.end(),trans < Aperson.problems.end(); cur++,trans++)
{
if(*cur == *trans)
common++;
}
if(common >= threshold)
return true;
else return false;
}
void addAfriend(Person aper)
{
if(judgeFriends(aper))
friends.push_back(aper);
}
};
int main()
{
ifstream in("input.txt");
cin.rdbuf(in.rdbuf());
vector<Person> person;
int num,numOfProblems;
cin>>num>>numOfProblems;
while(num--)
{
Person t;
t.input(numOfProblems);
person.push_back(t);
}
vector<Person>::iterator iter1,iter2;
for(iter1 = person.begin(); iter1 < person.end(); iter1++)
for(iter2 = person.begin(); iter2 < person.end(); iter2++)
{
if(iter1 != iter2)
iter1->addAfriend(*iter2);
}
for(iter1 = person.begin(); iter1 < person.end(); iter1++)
iter1->output();
return 0;
}
using namespace std;
class Person
{
private:
string name;
vector<Person> friends;
int threshold;
vector<char> problems;
public:
Person(){}
void input(int n)
{
cin>>name;
for(int i = 0; i < n; i++)
{
char tem;
cin>>tem;
problems.push_back(tem);
}
cin>>threshold;
}
void output()
{
vector<Person>::iterator iter;
cout<<name<<"'s friends are: ";
if(friends.empty())
cout<<"NONE"<<endl;
else
{
iter = friends.begin();
cout<<iter->name;
for(iter = friends.begin()+1; iter < friends.end(); iter++)
cout<<","<<iter->name;
cout<<endl;
}
}
bool judgeFriends(Person &Aperson)
{
vector<char>::iterator cur,trans;
int common = 0;
for(cur = problems.begin(),trans = Aperson.problems.begin(); cur < problems.end(),trans < Aperson.problems.end(); cur++,trans++)
{
if(*cur == *trans)
common++;
}
if(common >= threshold)
return true;
else return false;
}
void addAfriend(Person aper)
{
if(judgeFriends(aper))
friends.push_back(aper);
}
};
int main()
{
ifstream in("input.txt");
cin.rdbuf(in.rdbuf());
vector<Person> person;
int num,numOfProblems;
cin>>num>>numOfProblems;
while(num--)
{
Person t;
t.input(numOfProblems);
person.push_back(t);
}
vector<Person>::iterator iter1,iter2;
for(iter1 = person.begin(); iter1 < person.end(); iter1++)
for(iter2 = person.begin(); iter2 < person.end(); iter2++)
{
if(iter1 != iter2)
iter1->addAfriend(*iter2);
}
for(iter1 = person.begin(); iter1 < person.end(); iter1++)
iter1->output();
return 0;
}