fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main() {
  5. // your code goes here
  6. string a,b;
  7. cin>>a;
  8. cin>>b;
  9. unordered_map<char,int>m1;
  10. unordered_map<char,int>m2;
  11. for(int i=0;i<a.size();i++){
  12. m1[a[i]]++;
  13. }
  14. for(int i=0;i<b.size();i++){
  15. m2[b[i]]++;
  16. }
  17. int mini=1e9;
  18. for(int i=0;i<b.size();i++){
  19. if(m1.find(b[i])==m1.end()){
  20. cout<<"0";
  21. }
  22. int value=m1[b[i]]/m2[b[i]];
  23. mini=min(value,mini); //becuase we try to remove the each character from the given string that contain the target string characters so it must contain all the elements as well to we take minimum
  24.  
  25. }
  26. if(mini==1e9){
  27. cout<<"-1";
  28. }
  29. cout<<mini;
  30.  
  31.  
  32.  
  33. return 0;
  34. }
Success #stdin #stdout 0s 5320KB
stdin
mononom
mon
stdout
2