Remove characters from a numeric string such that string becomes divisible by 8 | C # program to remove digits from a numeric string such that the number becomes divisible by 8 ; Function that return true if sub is a sub - sequence in s ; Function to return a multiple of 8 formed after removing 0 or more characters from the given string ; Iterate over all multiples of 8 ; If current multiple exists as a subsequence in the given string ; Driver Code
using System ; class GFG { static bool checkSub ( string sub , string s ) { int j = 0 ; for ( int i = 0 ; i < s . Length ; i ++ ) if ( sub [ j ] == s [ i ] ) j ++ ; return j == sub . Length ; } static int getMultiple ( string s ) { for ( int i = 0 ; i < 1e3 ; i += 8 ) { if ( checkSub ( i . ToString ( ) , s ) ) return i ; } return - 1 ; } static void Main ( ) { string s = "3454" ; Console . WriteLine ( getMultiple ( s ) ) ; } }