fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. void hhh() {
  5. ios_base::sync_with_stdio(0);
  6. cin.tie(0);
  7. }
  8. typedef long long ll ;
  9.  
  10. struct cmp {
  11. bool operator() (const string &a, const string &b) const {
  12. if (a.size() == b.size()) return a < b;
  13. else return a.size() < b.size();
  14. }
  15. };
  16.  
  17.  
  18. int main() {
  19. hhh();
  20. int t ;
  21. cin >> t ;
  22. cin.ignore();
  23. while( t--) {
  24. string word;
  25. getline(cin, word);
  26. string del ;
  27. getline( cin, del);
  28. // nhap
  29.  
  30. stringstream ss(word);
  31. set< string, cmp > str;
  32. while( ss >> word) {
  33. str.insert(word);
  34. }
  35. // split string str
  36.  
  37. set <string, cmp > delStr;
  38. stringstream ss1(del);
  39. while( ss1 >> del) {
  40. delStr.insert(del);
  41. }
  42. // split string delStr
  43. //Theo độ dài tăng dần.
  44. //Nếu cùng độ dài thì theo thứ tự từ điển tăng dần.
  45. vector <string > res;
  46. for( auto x : str) {
  47. int fl = 1 ;
  48. for( auto y : delStr) {
  49. if( y == x) fl = 0 ;
  50. }
  51. if( fl ) res.emplace_back(x) ;
  52. }
  53. for( int i = 0 ; i < res.size() ; i++){
  54. ( i < res.size() - 1 ) ? ( cout << res[i] <<" ") : cout << res[i];
  55. }
  56.  
  57. cout << "\n";
  58. }
  59. }
  60.  
Success #stdin #stdout 0.01s 5320KB
stdin
3
anh dung handsome vecelo
vecelo
cat dog bird cat fish
dog elephant
xoo xoo yyy z
yyy z zzz
stdout
anh dung handsome
cat bird fish
xoo