Guest User

Untitled

a guest
Jun 23rd, 2018
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.64 KB | None | 0 0
  1. #include<iostream>
  2. #include<set>
  3. #include<string>
  4. #include<vector>
  5. #include<algorithm>
  6.  
  7. using namespace std;
  8. string names[100],str;
  9. set<string> friends[100];
  10. char q;
  11. int a,b,c,d,e,f,n;
  12.  
  13.  
  14. int main() {
  15.     //ifstream fin("input.txt");
  16.     //ofstream fout("output.txt");
  17.  
  18.     cin>>n;
  19.  
  20.     for (a=0;a<n;a++) {              
  21.          cin>>names[a];
  22.          for (b=0;b<6;b++) cin>>q;
  23.          while (111) {
  24.          getline(cin,str);
  25.          int pos,last=0;
  26.          
  27.          while ( (( pos = str.find("<friend>",last)) != -1)) {  
  28.              pos+=8;
  29.              string vfri = "";
  30.              while (str[pos]!='<') vfri+=str[pos++];
  31.              last=pos+9;  
  32.  
  33.              if (vfri!=names[a]) friends[a].insert(vfri);   }
  34.  
  35.          if (str.length() >= 7 && str.substr(str.length()-7,7)  == "</blog>" ) break; }  }
  36.  
  37.  
  38.     for (a=0;a<n;a++) {
  39.         cout<<names[a]<<'\n';
  40.         cout<<"1: ";
  41.         set<string>::iterator it=friends[a].begin();
  42.         if (!friends[a].empty() ) {
  43.             cout<< *friends[a].begin();
  44.             it++;
  45.             for ( ; it!=friends[a].end() ; it++)
  46.                 cout<<", "<<*it; }
  47.  
  48.         cout<<'\n'<<"2: ";
  49.         set<string> vfriends;
  50.        
  51.         for (b=0;b<n;b++) {
  52.             if (friends[b].find(names[a]) != friends[b].end() )
  53.                 vfriends.insert(names[b]); }
  54.             if (!vfriends.empty() ) {
  55.                 it=vfriends.begin();
  56.                 cout<<*it;
  57.                 it++;
  58.                 for ( ; it!=vfriends.end() ;it++) cout<<", "<<*it; }
  59.  
  60.             cout<<'\n'<<"3: ";
  61.             vector<string> bothfriends(100);
  62.             set_intersection( friends[a].begin(),friends[a].end(),vfriends.begin(),vfriends.end(),bothfriends.begin() );
  63.             if (bothfriends[0]!="") cout<<bothfriends[0];
  64.             for (c=1; c<100 && bothfriends[c]!="";c++)
  65.                 cout<<", "<<bothfriends[c];    
  66.             cout<<'\n'<<'\n';}
  67.  
  68.     return 0; }
Add Comment
Please, Sign In to add comment