Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <vector>;
- #include <algorithm>
- using namespace std;
- void preob(vector<int>& m, string& s, int x) {
- for (int i = 0 + x; i < s.size(); i++) {
- m.push_back(s[i] - '0');
- }
- }
- bool comp(int& x1, int& x2) {
- return x1 > x2;
- }
- void reverse_preob(int& x, vector<int>& s) {
- int nul = 0;
- int temp = 1;
- for (int i = s.size() - 1; i >= 0; i--) {
- x += s[i] * temp;
- temp *= 10;
- }
- }
- int main() {
- std::ifstream fin("input.txt");
- std::ofstream fout("output.txt");
- string a, b;
- fin >> a >> b;
- vector<int> temp_a, temp_b;
- bool f = false;
- if (a[0] == '-') {
- int min = a[1] - '0';
- for (int i = 2; i < a.size(); i++) {
- if (a[i] - '0' < min && a[i] != '0') {
- min = a[i] - '0';
- swap(a[i], a[1]);
- }
- }
- temp_a.push_back(min);
- preob(temp_a, a, 2);
- sort(temp_a.begin() + 1, temp_a.end());
- f = true;
- }
- else {
- preob(temp_a, a, 0);
- sort(temp_a.begin(), temp_a.end(), comp);
- }
- int kb = 0;
- if (b[0] == '-') {
- preob(temp_b, b, 1);
- sort(temp_b.begin(), temp_b.end(), comp);
- reverse_preob(kb, temp_b);
- kb *= -1;
- }
- else{
- int min = b[0] - '0';
- for (int i = 1; i < b.size(); i++) {
- if (b[i] - '0' < min && b[i] - '0' != 0) {
- min = b[i] - '0';
- swap(b[i], b[0]);
- }
- }
- temp_b.push_back(min);
- preob(temp_b, b, 1);
- sort(temp_b.begin() + 1, temp_b.end());
- reverse_preob(kb, temp_b);
- }
- int ka = 0;
- reverse_preob(ka, temp_a);
- if (f) {
- ka *= -1;
- }
- fout << ka - kb << endl;
- return 0;
- }
Add Comment
Please, Sign In to add comment