0

I want to insert the substring into the main string after sorting the main string. How can I do that??

Like,

ilovecoding after sorting cdegiilnoov. And after that let say substring eco, it should be inserted as decogiilnov.

#include <bits/stdc++.h>
using namespace std;

int main(){

int tc;
string s,a;
cin>>tc;

while(tc--){
    cin>>s>>a;
    sort(s.begin(), s.end());
    cout<<s<<endl;


}

return 0;
}

I got stuck here, also tried many times, till here I think everything is correct...

1 Answers1

1

I'm not sure if this is desired output or not, but you can check this function(include string header):

string process(string& main,string& sub){
  for (int i = 0; i < sub.size() ; i++){
      size_t pos = main.find(sub[i]);
      main.erase(pos,1);
  }
main.insert(1,sub);
return main;
}

and check here: Why should I not #include <bits/stdc++.h>?

Mehdi Mostafavi
  • 880
  • 1
  • 12
  • 25