Check if the number is valid when flipped upside down | C ++ implementation of the approach ; Function that returns true if str is Topsy Turvy ; For every character of the string ; If the current digit cannot form a valid digit when turned upside - down ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; bool topsyTurvy ( string str ) { for ( int i = 0 ; i < str . length ( ) ; i ++ ) { if ( str [ i ] == '2' str [ i ] == '4' str [ i ] == '5' str [ i ] == '6' str [ i ] == '7' str [ i ] == '9' ) { return false ; } } return true ; } int main ( ) { string str = "1234" ; if ( topsyTurvy ( str ) ) cout << " Yes " ; else cout << " No " ; return 0 ; }