str test

ron555 · updated May 14, 2022
#include <iostream>
using namespace std;


int main() {
    
            long power = 2;
            
            
            string subS = "9163574346363325007361058";
            
            long split = subS.size() - power;
            long len = power;

            long temp;
            std::string element;
            
            int i = subS.size();

            if (subS.size()%power == 0){

            while (i > 0 ){
                element = subS.substr(split, len);
                temp = stol(element);
                cout << "temp :" << temp << endl;
                i= i - power;
                
                split = split - power;
            }
            }
            
        else{
                while (i > (subS.size()%power) ){
                    element = subS.substr(split, len);
                    temp = stol(element);
                    cout << "temp :" << temp << endl;
                    i= i - power;
                
                    split = split - power;
                }
                
                cout << "i:" << i << endl;
                
                if (i = (subS.size()%power)){
                element = subS.substr(0, subS.size()%power);
                    temp = stol(element);
                    cout << "temp :" << temp << endl;
                    i= i - power;
                
                    split = split - power;
                }
                
        }
    
}
Output
(Run the program to view its output)

Comments

Please sign up or log in to contribute to the discussion.