Saleh127

uva 10252

Sep 25th, 2020 (edited)
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.82 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define ll long long
  4. #define test int t; cin>>t; for(int cs=1;cs<=t;cs++)
  5. int main()
  6. {
  7. string a, b;
  8. while (getline(cin, a), getline(cin, b))
  9. {
  10. int aCounts[128], bCounts[128];
  11. for (int i = 'a'; i <= 'z'; ++i)
  12. aCounts[i] = bCounts[i] = 0;
  13.  
  14. for (int i = 0; i < a.size(); ++i)
  15. ++aCounts[a[i]];
  16.  
  17. for (int i = 0; i < b.size(); ++i)
  18. ++bCounts[b[i]];
  19.  
  20. string longest = "";
  21.  
  22.  
  23. for (int i = 'a'; i <= 'z'; ++i)
  24. while (aCounts[i] > 0 && bCounts[i] > 0)
  25. {
  26. longest += (char) i;
  27. --aCounts[i];
  28. --bCounts[i];
  29. }
  30.  
  31. cout << longest << '\n';
  32. }
  33. }
Add Comment
Please, Sign In to add comment