text: Count of strings possible by replacing two consecutive same character with new character | C # program to count the different possible string form by replacing two same characters with one ; Array to find the fibonacci sequence ; Function to find the fibonacci sequence ; Function to count all possible strings ; Initialize ans = 1 ; If two consecutive char are same increase cnt ; Else multiply the fib [ cnt ] to ans and initialize ans to 1 ; If str = abcdeeee , then for last " eeee " the count munst be updated ; Return the total count ; Driver 's Code ; Function to precompute all the fibonacci number ; Function call to find the count
code: using System ; class GFG { static int [ ] fib = new int [ 100005 ] ; static void computeFibonacci ( ) { fib [ 0 ] = 1 ; fib [ 1 ] = 1 ; for ( int i = 2 ; i < 100005 ; i ++ ) { fib [ i ] = fib [ i - 1 ] + fib [ i - 2 ] ; } } static int countString ( string str ) { int ans = 1 ; int cnt = 1 ; for ( int i = 1 ; i < str . Length ; i ++ ) { if ( str [ i ] == str [ i - 1 ] ) { cnt ++ ; } else { ans = ans * fib [ cnt ] ; cnt = 1 ; } } ans = ans * fib [ cnt ] ; return ans ; } public static void Main ( string [ ] args ) { string str = " abdllldefkkkk " ; computeFibonacci ( ) ; Console . WriteLine ( countString ( str ) ) ; } }