Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<set>
- #include<string>
- #include<vector>
- #include<algorithm>
- using namespace std;
- string names[100],str;
- set<string> friends[100];
- char q;
- int a,b,c,d,e,f,n;
- int main() {
- //ifstream fin("input.txt");
- //ofstream fout("output.txt");
- cin>>n;
- for (a=0;a<n;a++) {
- cin>>names[a];
- for (b=0;b<6;b++) cin>>q;
- while (111) {
- getline(cin,str);
- int pos,last=0;
- while ( (( pos = str.find("<friend>",last)) != -1)) {
- pos+=8;
- string vfri = "";
- while (str[pos]!='<') vfri+=str[pos++];
- last=pos+9;
- if (vfri!=names[a]) friends[a].insert(vfri); }
- if (str.length() >= 7 && str.substr(str.length()-7,7) == "</blog>" ) break; } }
- for (a=0;a<n;a++) {
- cout<<names[a]<<'\n';
- cout<<"1: ";
- set<string>::iterator it=friends[a].begin();
- if (!friends[a].empty() ) {
- cout<< *friends[a].begin();
- it++;
- for ( ; it!=friends[a].end() ; it++)
- cout<<", "<<*it; }
- cout<<'\n'<<"2: ";
- set<string> vfriends;
- for (b=0;b<n;b++) {
- if (friends[b].find(names[a]) != friends[b].end() )
- vfriends.insert(names[b]); }
- if (!vfriends.empty() ) {
- it=vfriends.begin();
- cout<<*it;
- it++;
- for ( ; it!=vfriends.end() ;it++) cout<<", "<<*it; }
- cout<<'\n'<<"3: ";
- vector<string> bothfriends(100);
- set_intersection( friends[a].begin(),friends[a].end(),vfriends.begin(),vfriends.end(),bothfriends.begin() );
- if (bothfriends[0]!="") cout<<bothfriends[0];
- for (c=1; c<100 && bothfriends[c]!="";c++)
- cout<<", "<<bothfriends[c];
- cout<<'\n'<<'\n';}
- return 0; }
Add Comment
Please, Sign In to add comment