Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- *
- * Solution to homework assignment 1
- * Introduction to programming course
- * Faculty of Mathematics and Informatics of Sofia University
- * Winter semester 2021/2022
- *
- * @author Monika Dobrinova
- * @idnumber 8MI0600008
- * @task 2
- * @compiler VC
- *
- */
- #include <iostream>
- using namespace std;
- int main()
- {
- int n;
- cin >> n;
- if (n >= 1 && n <=9)
- {
- cout << n << endl;
- return 0;
- }
- int temp = n;
- int count = 0;
- while (temp)
- {
- temp /= 10;
- count++;
- }
- int pow = 1;
- int left = 0;
- int right = 0;
- for (int i = 1; i < count; i++)
- {
- pow *= 10;
- }
- while (n)
- {
- right = n % 10;
- left = n / pow;
- if (left > right)
- {
- cout << left << " ";
- }
- else if (right > left)
- {
- cout << right << " ";
- }
- if (pow == 1)
- {
- cout << n << " ";
- break;
- }
- n %= pow;
- n /= 10;
- pow /= 100;
- }
- cout << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement