A. Display The Number--------------思维+贪心/水

**You have a large electronic screen which can display up to 998244353 decimal digits. The digits are displayed in the same way as on different electronic alarm clocks: each place for a digit consists of 7 segments which can be turned on and off to compose different digits. The following picture describes how you can display all 10 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 1, you have to turn on 2 segments of the screen, and if you want to display 8, all 7 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 n 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 n segments.

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

Input
The first line contains one integer t (1≤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 n (2≤n≤105) — the maximum number of segments that can be turned on in the corresponding testcase.

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

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

Example
inputCopy

2
3
4
outputCopy
7
11

题意:
0~9数字由不同数目的火柴棒组成,现在题目给出火柴棒数量,让你用这些火柴棒组成一个最大数。
解析:
位数越多,数就越大
我们找到1,1是最少木棒组成的。但这还不够加入现在给你7个木棒全部用1的话,答案是111,是错误的。正确答案是711.所以我们还需要判断n是不是奇数如果是输出一个7,剩下的都输出1即可。


#include<bits/stdc++.h>
using namespace std;
map<int,int> v;
int t;
int main()
{
	cin>>t;
	int x;
	while(t--)
	{
		cin>>x;
		if(x&1) 
		{
			cout<<7;
			x-=3;
		}
		while(x)
		{
			cout<<1;
			x-=2;
		} 
		cout<<endl;
	}
}
发布了383 篇原创文章 · 获赞 7 · 访问量 8040

猜你喜欢

转载自blog.csdn.net/qq_43690454/article/details/104237654