Converting string to integer array for ease of computations ( Indexing in arr [ ] is considered to be starting from 1 )
int l = str . length ( ) ; int arr [ l ] ; for ( int i = 0 ; i < l ; i ++ ) arr [ i ] = str [ i ] - '0' ;