Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cmath>
- #include <string>
- using namespace std;
- int main()
- {
- string s;
- string t;
- string l;
- int a[100000]={0};
- int b[100000]={0};
- int max1=-10;
- int max2=-100;
- cin>>s;
- cin>>t;
- for(int i=0;i<s.length();i++){
- int h=s[i]-48;
- a[h]++;
- if(h>max1){
- max1=h;
- }
- }
- for(int i=0;i<t.length();i++){
- int h=t[i]-48;
- b[h]++;
- if(h>max2){
- max2=h;
- }
- }
- max1=max(max1,max2);
- for(int i=max1;i>=0;i--){
- while(a[i]>0 && b[i]>0){
- char k=i+48;
- l+=k;
- a[i]--;
- b[i]--;
- }
- }
- if(l==""){
- cout<<-1;
- return 0;
- }
- else{
- cout<<l;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement