Check length of a string is equal to the number appended at its last | C ++ program to check if size of string is appended at the end or not . ; Function to find if given number is equal to length or not ; Traverse string from end and find the number stored at the end . x is used to store power of 10. ; Check if number is equal to string length except that number 's digits ; Drivers code
#include <bits/stdc++.h> NEW_LINE using namespace std ; bool isequal ( string str ) { int n = str . length ( ) ; int num = 0 , x = 1 , i = n - 1 ; for ( i = n - 1 ; i >= 0 ; i -- ) { if ( '0' <= str [ i ] && str [ i ] <= '9' ) { num = ( str [ i ] - '0' ) * x + num ; x = x * 10 ; if ( num >= n ) return false ; } else break ; } return num == i + 1 ; } int main ( ) { string str = " geeksforgeeks13" ; isequal ( str ) ? cout << " Yes " : cout << " No " ; return 0 ; }