fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main() {
  5.  
  6. string s1, s2; cin>>s1>>s2;
  7.  
  8. // each char of s2 must present in s1 so that we can cnt how many times s2 is coming in s1.
  9. // for that we will push char of both string in two different map(mp1 & mp) & if any char of s2 is
  10. // not present in mp2 then we can say we will not get s2 in s1 for any no. of time.
  11.  
  12. unordered_map<char, int> mp1; // to store the char of s1
  13. unordered_map<char, int> mp2; // to store the char of s2
  14.  
  15. for(int i=0; i<s1.size(); i++) mp1[s1[i]]++;
  16.  
  17. for(int i=0; i<s2.size(); i++) mp2[s2[i]]++;
  18.  
  19.  
  20. int ans=1e9;
  21.  
  22. for(char ch='a'; ch<='z'; ch++) {
  23.  
  24. if(mp2.find(ch)!=mp2.end() && mp1.find(ch)==mp1.end())
  25. {
  26. ans=0;
  27. break;
  28. }
  29.  
  30. if(mp1.find(ch)!=mp1.end() && mp2.find(ch) !=mp2.end()) {
  31. int cnt = mp1[ch] / mp2[ch];
  32.  
  33. ans=min(ans, cnt);
  34. }
  35. }
  36.  
  37. cout<<ans<<" ";
  38.  
  39. return 0;
  40. }
Success #stdin #stdout 0.01s 5288KB
stdin
Standard input is empty
stdout
1000000000