Skip to content
Programmingoneonone
Programmingoneonone
  • Home
  • CS Subjects
    • Internet of Things (IoT)
    • Digital Communication
    • Human Values
  • Programming Tutorials
    • C Programming
    • Data structures and Algorithms
    • 100+ Java Programs
    • 100+ C Programs
  • HackerRank Solutions
    • HackerRank Algorithms Solutions
    • HackerRank C problems solutions
    • HackerRank C++ problems solutions
    • HackerRank Java problems solutions
    • HackerRank Python problems solutions
Programmingoneonone

HackerEarth Seven-Segment Display problem solution

YASH PAL, 31 July 2024
In this HackerEarth Seven-Segment Display problem solution, you all must have seen a seven-segment display. Alice got a number written in a seven-segment format where each segment was created used a matchstick.
Example: If Alice gets a number 123 so basically Alice used 12 matchsticks for this number. Alice is wondering what is the numerically largest value that she can generate by using at most the matchsticks that she currently possesses. Help Alice out by telling her that number.
hackerEarth Seven-Segment Display problem solution

HackerEarth Seven-Segment Display problem solution.

#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define MOD 1000000007
string s;
ll t,a[10];
void solve()
{
ll i,j,k;
cin>>t;
a[0]=a[6]=a[9]=6;
a[1]=2;
a[2]=a[3]=a[5]=5;
a[4]=4;
a[7]=3;
a[8]=7;
while(t--)
{
cin>>s;
ll val=0;
for(i=0;i<s.size();i++)
{
val+=a[s[i]-'0'];
}
if(val%2==1)
{
cout<<"7";
val-=3;
}
while(val>=2)
{
val-=2;
cout<<"1";
}
cout<<"n";
}
}
int main()
{

solve();
return 0;
}
coding problems solutions

Post navigation

Previous post
Next post

Pages

  • About US
  • Contact US
  • Privacy Policy

Programing Practice

  • C Programs
  • java Programs

HackerRank Solutions

  • C
  • C++
  • Java
  • Python
  • Algorithm

Other

  • Leetcode Solutions
  • Interview Preparation

Programming Tutorials

  • DSA
  • C

CS Subjects

  • Digital Communication
  • Human Values
  • Internet Of Things
  • YouTube
  • LinkedIn
  • Facebook
  • Pinterest
  • Instagram
©2025 Programmingoneonone | WordPress Theme by SuperbThemes