IF YOU HATE URSELF
Behold the glorious train wreck of code I\'ve concocted. Ever wonder what would happen if string manipulation and math had a baby that went rogue? Well, here it
Behold the glorious train wreck of code I\'ve concocted. Ever wonder what would happen if string manipulation and math had a baby that went rogue? Well, here it is\u2014a mutant fusion of nonsensical loops, baffling conditionals, and inexplicable logic gaps that defy all reasoning. It\'s like I blindfolded myself and tried to write code with my elbows. Somehow, it still runs... most of the time. Approach with caution; it\u2019s a testament to how far one can stretch the boundaries of acceptable C++ and human decency.\n\n###### **NOTE: The debugging for this code would not be possible without the help of friend, whose name u can find somewhere in this code.**\n\n# Intuition\nNo such intution, i write code on the go.\n\n# Approach\nSimple approach just use if else(not much ~16), for loops,and ton of string indexing to brute force my way through all test cases, so that U dont have to do it.\n\n# Complexity\n- Time complexity:\nEven though it\'s a shitty code, it\'s in O(n).\n\n- Space complexity:\nEven though it\'s a even shittier code, it\'s in O(1).\n\n# Code\n```cpp []\nclass Solution {\npublic:\n    int lcm(int a, int b) { return (a * b); }\n\n    string fractionAddition(string expression) {\n        int len = expression.length();\n        string ans;\n        int num, dem;\n\n        for (int i = 0; i < len - 2; i++) {\n            if (i == 0 && expression[i] == \'-\') {\n                if (expression[i+1] == \'1\' && expression[i+2] == \'0\') {\n                    num = -10;\n                    dem = (expression[i + 4] - \'0\');\n                    cout << num << endl << dem << endl << endl;\n                    i = i + 4;\n                    continue;\n                }\n                if (expression[i+3] == \'1\' && expression[i+4] == \'0\') {\n                    num = (expression[i + 1] - \'0\') * (-1);\n                    dem = 10;\n                    cout<<"mayank";\n                    cout << num << endl << dem << endl << endl;\n                    i = i + 4;\n                    continue;\n                }\n                num = (expression[i + 1] - \'0\') * (-1);\n                dem = (expression[i + 3] - \'0\');\n                cout << num << endl << dem << endl << endl;\n                i = i + 3;\n                continue;\n            } else if (i == 0) {\n                if (expression[i] == \'1\' && expression[i+1] == \'0\') {\n                    num = 10;\n                    dem = (expression[i + 3] - \'0\');\n                    cout << num << endl << dem << endl << endl;\n                    i = i + 3;\n                    continue;\n                }\n                if (expression[i+2] == \'1\' && expression[i+3] == \'0\') {\n                    num = (expression[i] - \'0\');\n                    dem = 10;\n                    cout<<"mayank";\n                    cout << num << endl << dem << endl << endl;\n                    i = i + 3;\n                    continue;\n                }\n                num = (expression[i] - \'0\');\n                dem = (expression[i + 2] - \'0\');\n                cout << num << endl << dem << endl << endl;\n                i = i + 2;\n                continue;\n            }\n\n            if (expression[i] == \'-\') {\n                if (expression[i+1] == \'1\' && expression[i+2] == \'0\') {\n                    num = num * (expression[i + 4] - \'0\') - 10 * dem;\n                    dem = (expression[i + 4] - \'0\') * dem;\n                    cout << num << endl << dem << endl << endl;\n                    i = i + 4;\n                    continue;\n                }\n                if (expression[i+3] == \'1\' && expression[i+4] == \'0\') {\n                    num = (num * 10 - (expression[i + 1] - \'0\') * dem);\n                    dem = 10 * dem;\n                    cout<<"mayank";\n                    cout << num << endl << dem << endl << endl;\n                    i = i + 4;\n                    continue;\n                }\n                num = num * (expression[i + 3] - \'0\') - (expression[i + 1] - \'0\') * dem;\n                dem = dem * (expression[i + 3] - \'0\');\n                cout << num << endl << dem << endl << endl;\n                i = i + 3;\n                continue;\n            } else {\n                if (expression[i+1] == \'1\' && expression[i+2] == \'0\') {\n                    num = num * (expression[i + 4] - \'0\') + 10 * dem;\n                    dem = (expression[i + 4] - \'0\') * dem;\n                    cout << num << endl << dem << endl << endl;\n                    i = i + 4;\n                    continue;\n                }\n                if (expression[i+3] == \'1\' && expression[i+4] == \'0\') {\n                    num = num * 10 +\n                      (expression[i + 1] - \'0\') * dem;\n                    dem = 10 * dem;\n                    cout << num << endl << dem << endl << endl;\n                    i = i + 4;\n                    continue;\n                }\n                cout << expression[i] << expression[i + 1] << expression[i + 2]\n                     << expression[i + 3] << endl;\n                num = num * (expression[i + 3] - \'0\') +\n                      (expression[i + 1] - \'0\') * dem;\n                dem = lcm(dem, (expression[i + 3] - \'0\'));\n                cout << num << endl << dem << endl << endl;\n                i = i + 3;\n            }\n        }\n\n        if (abs(num) > abs(dem)) {\n            for (int i = abs(dem); i > 1; i--) {\n                if (abs(num) % i == 0 && abs(dem) % i == 0) {\n                    num = num / i;\n                    dem = dem / i;\n                }\n            }\n        } else {\n            for (int i = abs(num); i > 1; i--) {\n                if (abs(num) % i == 0 && abs(dem) % i == 0) {\n                    num = num / i;\n                    dem = dem / i;\n                }\n            }\n        }\n\n        if(num<0 && dem<0){\n            num = abs(num);\n            dem = abs(dem);\n        }\n\n        if (num == 0)\n            dem = 1;\n\n        string nums = to_string(num);\n        string dems = to_string(dem);\n\n        ans = nums + "/" + dems;\n\n        return ans;\n    }\n};\n```\n\nThank you for successfully wasting your time, even scrolling through this and reaching here!!
['C++']