5.31 选拔赛Display The Number

该篇博客探讨了一道编程题,题目要求在限制屏幕最多开启n个段的情况下,找出能显示的最大整数。由于7和1需要的屏幕条数最少,解题策略是尽可能多地使用7,其次是1。提供的C++代码实现了这个逻辑,对于偶数个屏幕条数,会输出等数量的1,对于奇数个,则先输出一个7再跟若干1。
摘要由CSDN通过智能技术生成

You have a large electronic screen which can display up to 998244353998244353 decimal digits. The digits are displayed in the same way as on different electronic alarm clocks: each place for a digit consists of 77 segments which can be turned on and off to compose different digits. The following picture describes how you can display all 1010 decimal digits:

As you can see, different digits may require different number of segments to be turned on. For example, if you want to display 11, you have to turn on 22 segments of the screen, and if you want to display 88, all 77 segments of some place to display a digit should be turned on.

You want to display a really large integer on the screen. Unfortunately, the screen is bugged: no more than nn segments can be turned on simultaneously. So now you wonder what is the greatest integer that can be displayed by turning on no more than nn segments.

Your program should be able to process tt different test cases.

Input

The first line contains one integer tt (1≤t≤1001≤t≤100) — the number of test cases in the input.

Then the test cases follow, each of them is represented by a separate line containing one integer nn (2≤n≤1052≤n≤105) — the maximum number of segments that can be turned on in the corresponding testcase.

It is guaranteed that the sum of nn over all test cases in the input does not exceed 105105.

Output

For each test case, print the greatest integer that can be displayed by turning on no more than nn segments of the screen. Note that the answer may not fit in the standard 3232-bit or 6464-bit integral data type.

Example

Input

2
3
4

Output

7
11

 题目大意:给你n个可显示的屏幕条数,输出这n个可显示的屏幕条组成的最大数字

思路:分析题目可以发现7和1所需的屏幕条数最少,所以只需考虑7和1即可。

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
typedef long long ll;

int main()
{
	int n,t,a;
	scanf("%d",&t);
	
	while(t--)
	{
		scanf("%d",&n);
		
		if(n%2==0)
		{
			n/=2;
			while(n--)
			{
				printf("1");
			}
		}
		else
		{
			printf("7");
			n=(n-3)/2;
			while(n--)
			{
				printf("1");
			}
		}
		printf("\n");
	}
	return 0;
}

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值