Advertisement
Guest User

Untitled

a guest
Jul 21st, 2019
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.79 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3. #include <string>
  4.  
  5. using namespace std;
  6.  
  7. int main()
  8. {
  9.   string s;
  10.   string t;
  11.   string l;
  12.   int a[100000]={0};
  13.   int b[100000]={0};
  14.   int max1=-10;
  15.   int max2=-100;
  16.   cin>>s;
  17.   cin>>t;
  18.   for(int i=0;i<s.length();i++){
  19.         int h=s[i]-48;
  20.         a[h]++;
  21.         if(h>max1){
  22.             max1=h;
  23.         }
  24.   }
  25.   for(int i=0;i<t.length();i++){
  26.         int h=t[i]-48;
  27.             b[h]++;
  28.             if(h>max2){
  29.                 max2=h;
  30.             }
  31.   }
  32.   max1=max(max1,max2);
  33.   for(int i=max1;i>=0;i--){
  34.         while(a[i]>0 && b[i]>0){
  35.             char k=i+48;
  36.             l+=k;
  37.             a[i]--;
  38.             b[i]--;
  39.         }
  40.   }
  41.   if(l==""){
  42.     cout<<-1;
  43.     return 0;
  44.   }
  45.   else{
  46.     cout<<l;
  47.   }
  48.   return 0;
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement