fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main() {
  5. // max distance between same element
  6. // vector<int> arr={1,1,2,2,2,1};
  7. // unordered_map<int,int> ok;
  8. // int dist=0;
  9. // for(int i=0;i<arr.size();i++){
  10. // if(ok.find(arr[i])!=ok.end()){
  11. // dist=max(dist,i-ok[arr[i]]);
  12. // }else{
  13. // ok[arr[i]]=i;
  14. // }
  15.  
  16. // }
  17. // cout<<dist;
  18.  
  19. //find common character
  20. vector<string> words = {"acabcddd","bcbdbcbd","baddbadb","cbdddcac","aacbcccd","ccccddda","cababaab","addcaccd"};
  21. vector<char> ans;
  22. vector<int> ok(26,1000);
  23. for(int i=0;i<3;i++){
  24. vector<int> each(26,0);
  25. for(int j=0;j<words[i].length();j++){
  26. each[words[i][j]-'a']++;
  27. }
  28. for(char c='a';c<='z';c++){
  29. ok[c-'a']=min(ok[c-'a'] , each[c-'a']);
  30. }
  31. for(char c='a';c<='d';c++){
  32. cout<<ok[c-'a']<<" ";
  33. }
  34. cout<<endl;
  35. }
  36. for(char c='a';c<='z';c++){
  37. if(ok[c-'a']>=1){
  38. for(int i=0;i<ok[c-'a'];i++){
  39. ans.push_back(c);
  40. }
  41.  
  42. }
  43. }
  44. for(int i=0;i<ans.size();i++){
  45. cout<<ans[i]<<endl;
  46. }
  47. // for(char c='a';c<='z';c++){
  48. // cout<<c;
  49. // }
  50.  
  51.  
  52.  
  53.  
  54.  
  55.  
  56.  
  57.  
  58.  
  59. return 0;
  60. }
Success #stdin #stdout 0s 5320KB
stdin
Standard input is empty
stdout
2    1    2    3    
0    1    2    2    
0    1    0    2    
b
d
d