Advertisement
OnyRoman

Untitled

Oct 12th, 2019
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.86 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. using namespace std;
  4.  
  5. ifstream fin("NUMAR.TXT");
  6.  
  7. int main() {
  8. long n, m;
  9. fin >> n;
  10. bool cifra = false;
  11. int x = 1, v[10];
  12. while (!cifra) {
  13. int c = n % 10;
  14. n /= 10;
  15. if (n == 0) {
  16. cout << "Nu exista";
  17. return 0;
  18. }
  19. if (c > n % 10) {
  20. cifra = true;
  21. m = n / 10 * 10 + c;
  22. v[x] = n % 10;
  23. x++;
  24. }
  25. else {
  26. v[x] = c;
  27. x++;
  28. }
  29. }
  30.  
  31. x--;
  32. int vmin = 0;
  33. while (vmin != 10) {
  34. vmin = 10;
  35. for (int i = 1; i <= x; i++)
  36. if (v[i] < vmin) {
  37. vmin = v[i];
  38. v[i] = 10;
  39. }
  40. if (vmin != 10)
  41. m = m * 10 + vmin;
  42. }
  43. cout << m;
  44. return 0;
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement