Check if given string contains all the digits | C ++ implementation of the approach ; Function that returns true if ch is a digit ; Function that returns true if str contains all the digits from 0 to 9 ; To mark the present digits ; For every character of the string ; If the current character is a digit ; Mark the current digit as present ; For every digit from 0 to 9 ; If the current digit is not present in str ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; const int MAX = 10 ; bool isDigit ( char ch ) { if ( ch >= '0' && ch <= '9' ) return true ; return false ; } bool allDigits ( string str , int len ) { bool present [ MAX ] = { false } ; for ( int i = 0 ; i < len ; i ++ ) { if ( isDigit ( str [ i ] ) ) { int digit = str [ i ] - '0' ; present [ digit ] = true ; } } for ( int i = 0 ; i < MAX ; i ++ ) { if ( ! present [ i ] ) return false ; } return true ; } int main ( ) { string str = " Geeks12345for69708" ; int len = str . length ( ) ; if ( allDigits ( str , len ) ) cout << " Yes " ; else cout << " No " ; return 0 ; }