3
string reformatNumber(string number) {4
string temp; // stores the digits from string number5
string ans; // stores final answer9
if (isdigit(ch)) temp += ch;11
int len = temp.size();15
// check for different values of "len"16
if (len > 4) { // if len > 4 -> make grp of 3 digits17
ans += temp.substr(i, i + 3);23
else if (len == 3) { // if len == 3 -> make grp of 3 digits24
ans += temp.substr(i, i + 3);30
else if (len == 2) { // if len == 2 -> make grp of 2 digits31
ans += temp.substr(i, i + 2);37
else if (len == 4) { // if len == 4 -> make 1 grp of 2 digits & reduce the38
// length by 2 units, in the next iteration it will39
// automatically catch (len==2) condition40
ans += temp.substr(i, i + 2);43
// ans += temp.substr(i,i+2); ------(1)44
// temp.erase(i,2); ------(2)45
// ans += "-"; ------(3)46
len = len - 2; // *len = len-4* can be edited to *len = len-2*------(4)