Advertisement
Kali_prasad

print the min lexographic order of main string which contains the pattern string (qk18)

Apr 8th, 2022
35
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.49 KB | None | 0 0
  1. #pragma GCC optimize ("O3")
  2. #pragma GCC target ("sse4")
  3.  
  4. #include <bits/stdc++.h>
  5. using namespace std;
  6.  
  7. typedef long long ll;
  8. typedef pair<int, int> pii;
  9. typedef pair<string,int> psi;
  10. typedef map<int,int> mii;
  11. typedef map<long long,long long> mll;
  12. typedef map<string,int> msi;
  13. typedef map<char,int> mci;
  14. typedef set<int> si;
  15. typedef set<long long> sll;
  16. typedef set<string> ss;
  17. typedef set<char> sc;
  18. typedef vector<int> vi;
  19. typedef vector<string> vs;
  20. typedef vector<char> vc;
  21. typedef vector<ll> vll;
  22. typedef vector<vector<int>> vvi;
  23. typedef vector<vector<string>> vvs;
  24. typedef vector<vector<ll>> vvll;
  25.  
  26. #define FOR(i, a, b) for (auto i=a; i<=(b); i++)
  27. #define FORd(i,b,a) for (int i =b; i >= a; i--)
  28. #define sz(x) (int)(x).size()
  29. #define mp make_pair
  30. #define pb push_back
  31. #define f first
  32. #define s second
  33. #define ins insert
  34.  
  35. const int MOD = 1000000007;
  36. //type functions here
  37.  
  38.  
  39.  
  40. int main() {
  41.  
  42.     int tc=1;
  43.     //cin>>tc;
  44.     FOR(w,1,tc)
  45.     {
  46.         mci m1,m2;
  47.         string s1="a",s2="a";
  48.         //cin>>s1>>s2;
  49.         for(auto x:s1) m1[x]++;
  50.         for(auto x:s2) m2[x]++;
  51.         for(auto x:m2) m1[x.f]-=x.s;//deleting the pattern chars from the big string
  52.        
  53.         string s="";
  54.         int flag=0;
  55.         for(auto x:m1)
  56.         {
  57.               while(x.s)
  58.             {
  59.                 s+=x.f;
  60.                 x.s--;
  61.             }
  62.             if(x.f>=s2[0]&&flag==0)
  63.             {s+=s2;
  64.             flag=1;
  65.             }
  66.            
  67.          
  68.              
  69.         }
  70.         cout<<s<<endl;
  71.        
  72.     }
  73.     return 0;
  74. }
  75.  
  76.  
  77.  
  78.  
  79.  
  80.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement