Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- using namespace std;
- ifstream fin("NUMAR.TXT");
- int main() {
- long n, m;
- fin >> n;
- bool cifra = false;
- int x = 1, v[10];
- while (!cifra) {
- int c = n % 10;
- n /= 10;
- if (n == 0) {
- cout << "Nu exista";
- return 0;
- }
- if (c > n % 10) {
- cifra = true;
- m = n / 10 * 10 + c;
- v[x] = n % 10;
- x++;
- }
- else {
- v[x] = c;
- x++;
- }
- }
- x--;
- int vmin = 0;
- while (vmin != 10) {
- vmin = 10;
- for (int i = 1; i <= x; i++)
- if (v[i] < vmin) {
- vmin = v[i];
- v[i] = 10;
- }
- if (vmin != 10)
- m = m * 10 + vmin;
- }
- cout << m;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement