Check if number can be displayed using seven segment led | C ++ implementation of above approach ; Pre - computed values of segment used by digit 0 to 9. ; Check if it is possible to display the number ; Finding sum of the segments used by each digit of the number ; Driven Program ; Function call to print required answer
#include <bits/stdc++.h> NEW_LINE using namespace std ; const int seg [ 10 ] = { 6 , 2 , 5 , 5 , 4 , 5 , 6 , 3 , 7 , 6 } ; string LedRequired ( string s , int led ) { int count = 0 ; for ( int i = 0 ; i < s . length ( ) ; ++ i ) { count += seg [ int ( s [ i ] ) - 48 ] ; } if ( count <= led ) return " YES " ; else return " NO " ; } int main ( ) { string S = "123456789" ; int led = 20 ; cout << LedRequired ( S , led ) << endl ; return 0 ; }