Advertisement
Guest User

Untitled

a guest
Dec 15th, 2019
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.88 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4.  
  5. int main()
  6. {
  7. int q;
  8. cin>>q;
  9. string ans[1500];
  10. for(int i=0;i<q;i++)
  11. {
  12. string a,b;
  13. cin>>a>>b;
  14. int c = min(a.size(),b.size());
  15. int j=0;
  16. while (j<c)
  17. {
  18. if (a[j]<b[j])
  19. {
  20. break;
  21. }
  22. else
  23. {
  24. if (a[j]==b[j])j++;
  25. else if (a[j]>b[j])
  26. {
  27. for (int k=j+1;k<c;k++)
  28. {
  29. if(a[k]<b[j])
  30. {
  31. char p=a[j];
  32. a[j]=a[k];
  33. a[k]=p;
  34. break;
  35. }
  36. else if(a[k]==b[j])
  37. {
  38. char p=a[j];
  39. a[j]=a[k];
  40. a[k]=p;
  41. }
  42. else if (k==c-1)
  43. {
  44. a="---";
  45. }
  46.  
  47. }
  48.  
  49. }
  50. }
  51. }
  52. cout<<a<<endl;
  53.  
  54.  
  55. }
  56.  
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement