Separate the Numbers

  • + 0 comments

    Here is my easy C++ solution, explanation here : https://youtu.be/e32U19k1X6A

    void separateNumbers(string s) {
        int bl = 1;
        bool f = false;
        while(bl * 2 <= s.size()){
            string base = s.substr(0, bl);
            string newString = "";
            long baselong = atol(base.c_str());
            do{
                newString += to_string(baselong);
                baselong++;
            }while(newString.size() < s.size());
            if(newString == s) {cout << "YES " << base;f = true;break;}
            bl++;
        }
        if(!f) cout << "NO";
        cout << endl;
    }