Breaking a number such that first part is integral division of second by a power of 10 | c ++ function to count ways to divide a string in two parts a and b such that b / pow ( 10 , p ) == a ; substring representing int a ; no of digits in a ; consider only most significant l1 characters of remaining string for int b ; if any of a or b contains leading 0 s discard this combination ; if both are equal ; driver function to test above function
#include <bits/stdc++.h> NEW_LINE using namespace std ; int calculate ( string N ) { int len = N . length ( ) ; int l = ( len ) / 2 ; int count = 0 ; for ( int i = 1 ; i <= l ; i ++ ) { string s = N . substr ( 0 , i ) ; int l1 = s . length ( ) ; string t = N . substr ( i , l1 ) ; if ( s [ 0 ] == '0' t [ 0 ] == '0' ) continue ; if ( s . compare ( t ) == 0 ) count ++ ; } return count ; } int main ( ) { string N = "2202200" ; cout << calculate ( N ) ; return 0 ; }