Advertisement
extremq

Untitled

Oct 31st, 2020
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.51 KB | None | 0 0
  1. //Mihon Daniel
  2. #include <iostream>
  3. using namespace std;
  4. int main ()
  5. {
  6. int a,b,c,numar1,numar2,min1,min2,max1,max2,mij1,mij2;
  7. cin>>numar1>>numar2;
  8. ///memoram fiecare cifra din primul numar in variabilele a,b,c (a-cifra sutelor, b-cifra zecilor, c-cifra unitatilor)
  9. a=numar1/100;
  10. b=numar1/10%10;
  11. c=numar1%10;
  12. min1=max1=a;
  13. if (b<min1) min1=b; ///aflam cifra minima din primul numar
  14. if (c<min1) min1=c;
  15. if (b>max1) max1=b; ///aflam cifra maxima din primul numar
  16. if (c>max1) max1=c;
  17. mij1=a+b+c-min1-max1; ///aflam cifra din mijloc ca si valoare din primul numar
  18. ///repetam procesul de mai sus si cu al doilea numar
  19. a=numar2/100;
  20. b=numar2/10%10;
  21. c=numar2%10;
  22. min2=max2=a;
  23. if (b<min2) min2=b; ///aflam cifa minima din al doilea numar
  24. if (c<min2) min2=c;
  25. if (b>max2) max2=b; ///aflam cifra maxima din al doilea numar
  26. if (c>max2) max2=c;
  27. mij2=a+b+c-min2-max2; ///aflam cifra din mijloc ca valoare din al doilea numar
  28. ///afisam rezultatele in functie de caz
  29. if (max1>max2) cout<<max1*10+max2<<" "; ///afisam cel mai mare numar care se poate forma cu cifrele maxime
  30. else cout<<max2*10+max1<<" ";
  31. if (min1!=0 && min2!=0) ///daca cifrele minime sunt ambele diferite de zero
  32. {
  33. if (min1<min2) cout<<min1*10+min2;
  34. else cout<<min2*10+min1;
  35. }
  36. else
  37. {
  38. if (min1==0 && min2!=0)
  39. {
  40. if (mij1<min2 && mij1!=0) cout<<mij1*10+min2;
  41. else
  42. {
  43. if (max1<min2) cout<<max1*10+min2;
  44. else cout<<min2*10;
  45.  
  46. }
  47. }
  48. else
  49. if (min1!=0 && min2==0)
  50. {
  51. if (mij2<min1 && mij2!=0) cout<<mij2*10+min1;
  52. else
  53. {
  54. if (max2<min1) cout<<max2*10+min1;
  55. else cout<<min1*10;
  56. }
  57. }
  58. else
  59. {
  60. if (mij1!=0 && mij2!=0) ///daca valorile din mijloc sunt diferite de 0
  61. {
  62. if (mij1<mij2) cout<<mij1*10;
  63. else cout<<mij2*10;
  64. }
  65. else
  66. {
  67. if (mij1!=0 && mij2==0) cout<<mij1*10;
  68. else if (mij1==0 && mij2!=0) cout<<mij2*10;
  69. else
  70. {
  71. if (max1<max2) cout<<max1*10;
  72. else cout<<max2*10;
  73. }
  74. }
  75. }
  76. }
  77. return 0;
  78. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement