Check if a given number is Fancy | C # program to find if a given number is fancy or not ; To store mappings of fancy pair characters . For example 6 is paired with 9 and 9 is paired with 6. ; Find number of digits in given number ; Traverse from both ends , and compare characters one by one ; If current characters at both ends are not fancy pairs ; Driver Code
using System ; using System . Collections . Generic ; class GFG { static bool isFancy ( String num ) { Dictionary < char , char > fp = new Dictionary < char , char > ( ) ; fp . Add ( '0' , '0' ) ; fp . Add ( '1' , '1' ) ; fp . Add ( '6' , '9' ) ; fp . Add ( '8' , '8' ) ; fp . Add ( '9' , '6' ) ; int n = num . Length ; int l = 0 , r = n - 1 ; while ( l <= r ) { if ( ! fp . ContainsKey ( num [ l ] ) fp [ num [ l ] ] != num [ r ] ) return false ; l ++ ; r -- ; } return true ; } public static void Main ( String [ ] args ) { String str = "9088806" ; if ( isFancy ( str ) ) Console . WriteLine ( " Yes " ) ; else Console . WriteLine ( " No " ) ; } }