You all must have seen a seven segment display.If not here it is:

Alice got a number written in seven segment format where each segment was creatted 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 possess.Help Alice out by telling her that number.
Input Format:
First line contains T (test cases).
Next T lines contain a Number N.
Output Format:
Print the largest possible number numerically that can be generated using at max that many number of matchsticks which was used to generate N.
In C –
#include<stdio.h>
#include<string.h>
int main(void)
{
int t;
scanf(“%d”,&t);
while(t–)
{
int a[10]={6,2,5,5,4,5,6,3,7,6,},i,sum=0;
char n[100];
scanf(“%s”,n);
for(i=0;i<strlen(n);i++)
sum+= a[(n[i]-48)];
if(sum%2==1)
printf(“7”);
else
printf(“1”);
for(i=1;i<sum/2;i++)
printf(“1”);
printf(“\n”);
}
}
In Java –
import java.io.BufferedReader;
import java.io.InputStreamReader;
class TestClass {
public static void main(String args[] ) throws Exception {
int arr[]=new int[]{6,2,5,5,4,5,6,3,7,6};
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int test=Integer.parseInt(br.readLine());
StringBuilder str=new StringBuilder(“”);
while(test–!=0)
{
int count=0;
String st=br.readLine();
for(int i=0; i<st.length(); i++)
{
count+=arr[st.charAt(i)-‘0’];
}
if(count%2==1)
{
str.append(“7”);
count-=3;
for(int i=0; i<count; i+=2)
{
str.append(“1”);
}
}
else
{
for(int i=0; i<count; i+=2)
{
str.append(“1”);
}
}
str.append(“\n”);
}
System.out.println(str);
}
}
In Python –
def mat(m):
x = 0
match={
“0”: 6, “1”: 2,”2″:5, “3”: 5,
“4”: 4, “5”: 5, “6”: 6,
“7”: 3, “8”: 7,”9″: 6 }
for i in m :
x += match[i]
r = x % 2
result = [“1”]
if r == 0 :
result.append(x // 2)
result.append(“”)
elif r == 1:
result.append((x // 2)-1)
result.append(“7”)
return ((result[0] * result[1]) + result[2])
n = int(input())
while n!=0:
m = input()
print(mat(m)[::-1])
n = n-1
Code Explaination
This code defines a function called “mat” which takes a string argument “m”.
Within the function, there is a dictionary called “match” that maps each digit from 0 to 9 to the number of segments required to display it on a digital display. For example, the digit 0 requires 6 segments, the digit 1 requires 2 segments, and so on.
The function then iterates through each character in the string “m” and adds up the number of segments required to display each digit using the “match” dictionary.
After computing the total number of segments required, the function calculates the remainder of dividing this number by 2. If the remainder is 0, the function appends the number of segments divided by 2 to a list called “result”, along with an empty string. If the remainder is 1, the function appends the number of segments divided by 2 minus 1 to “result”, along with the string “7”.
Finally, the function concatenates the elements of the “result” list and returns the resulting string.
The code then prompts the user for an integer input “n” and enters a while loop that runs n times. Within each iteration of the loop, the code prompts the user for a string input “m”, passes it to the “mat” function, and prints the resulting string in reverse order (using slicing notation “[::-1]”). The loop decrements the value of “n” after each iteration until it reaches 0.