Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- #define int int64_t
- using namespace std;
- int32_t main()
- {
- int t;
- cin >> t;
- while (t--)
- {
- int n;
- vector <int> ans;
- cin >> n;
- ans.push_back(n);
- while (n > 9)
- {
- string s;
- s = to_string(n);
- if (s.size() == 2 && s [0] == s [1])
- break;
- int mid = s.size() / 2 + 1;
- if (!(s.size() & 1))
- {
- string s1 = s.substr(0, mid - 1);
- int i = stol(s1);
- s1 = s.substr(mid - 1, (int)s.size());
- int j = stol(s1);
- if (abs(i - j) == 0)
- {
- s1 = s.substr(0, mid - 2);
- i = stol(s1);
- s1 = s.substr(mid - 2, (int)s.size());
- j = stol(s1);
- int ans1 = abs(i - j), ans2;
- s1 = s.substr(0, mid);
- i = stol(s1);
- s1 = s.substr(mid, (int)s.size());
- j = stol(s1);
- ans2 = abs(i - j);
- n = min(ans1, ans2);
- }
- else
- n = abs(i - j);
- }
- else
- {
- string s1 = s.substr(0, mid - 1);
- int i = stol(s1);
- s1 = s.substr(mid - 1, s.size());
- int j = stol(s1);
- int ans1 = abs(i - j), ans2;
- if (ans1 == 0)
- ans1 = LLONG_MAX;
- s1 = s.substr(0, mid);
- i = stol(s1);
- s1 = s.substr(mid, s.size());
- j = stol(s1);
- ans2 = abs(i - j);
- if (ans2 == 0)
- ans2 = LLONG_MAX;
- n = min(ans1, ans2);
- }
- ans.push_back(n);
- }
- cout << ans.size() << " ";
- for(auto i: ans)
- cout << i << " ";
- cout << "\n";
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment