0
点赞
收藏
分享

微信扫一扫

寒假养成计划——Day1

        终于等到放寒假啦!寒假期间几乎每个工作日都有一些小练习,来恢复一下做题的感觉(bushi),博客基本上每天都会更新前一天的做题情况,维持一下自己“菜鸟”的水平。


A题

题目链接

You are given nn integers a1,a2,…,an. You choose any subset of the given numbers (possibly, none or all numbers) and negate these numbers (i. e. change x→(−x)). What is the maximum number of different values in the array you can achieve?

Input

The first line of input contains one integer t (1≤t≤100): the number of test cases.

The next lines contain the description of the t test cases, two lines per a test case.

In the first line you are given one integer n (1≤n≤100): the number of integers in the array.

The second line contains nn integers a1,a2,…,an (−100≤ai≤100).

Output

For each test case, print one integer: the maximum number of different elements in the array that you can achieve negating numbers in the array.

Example

input

3
4
1 1 2 2
3
1 2 3
2
0 0

output

4
3
1

Note

In the first example we can, for example, negate the first and the last numbers, achieving the array [−1,1,2,−2] with four different values.

In the second example all three numbers are already different.

In the third example negation does not change anything.


题解:

AC代码:

#include <bits/stdc++.h>
using namespace std;

int a[105],b[105];

int main()
{
	int t;
	scanf("%d",&t);
	while (t--)
	{
		memset(b,0,sizeof(b));
		int n;
		scanf("%d",&n);
		for (int i=1;i<=n;i++)
		{
			scanf("%d",&a[i]);
			b[abs(a[i])]++;
		}
		int sum=0;
		for (int i=0;i<=100;i++)
		{
			if (b[i]!=0)
			{
				if (i==0)
					sum++;
				else if (b[i]>=2)
					sum+=2;
				else
					sum+=b[i];
			}
		}
		printf("%d\n",sum);
	}
	return 0;
}

B题

题目链接

You have a string s1s2…sn and you stand on the left of the string looking right. You want to choose an index k (1≤k≤n) and place a mirror after the k-th letter, so that what you see is s1s2…sksksk−1…s1. What is the lexicographically smallest string you can see?

A string a is lexicographically smaller than a string b if and only if one of the following holds:

  • a is a prefix of b, but a≠b;
  • in the first position where a and b differ, the string a has a letter that appears earlier in the alphabet than the corresponding letter in b.

Input

The first line of input contains one integer t (1≤t≤10000): the number of test cases.

The next t lines contain the description of the test cases, two lines per a test case.

In the first line you are given one integer n (1≤n≤105): the length of the string.

The second line contains the string s consisting of n lowercase English characters.

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

Output

For each test case print the lexicographically smallest string you can see.

Example

input

4
10
codeforces
9
cbacbacba
3
aaa
4
bbaa

output

cc
cbaabc
aa
bb

Note

In the first test case choose k=1 to obtain "cc".

In the second test case choose k=3 to obtain "cbaabc".

In the third test case choose k=1 to obtain "aa".

In the fourth test case choose k=1 to obtain "bb".


 题解:

AC代码:

#include <bits/stdc++.h>
using namespace std;

int main()
{
	int t;
	scanf("%d",&t);
	while (t--)
	{
		int n;
		scanf("%d",&n);
		string s;
		cin>>s;
		if (n==1)
			cout<<s+s<<endl;
		else
		{
			string tmp="";
			bool f=0;
			for (int i=1;i<n;i++)
			{
				if (i==1&&s[i]==s[i-1])
				{
					tmp+=s[i];
					tmp+=s[i];
					f=1;
					break;
				}
				else
				{
					if (s[i]<=s[i-1])
					{
						tmp+=s[i-1];
						if (i==n-1&&s[i]<=s[i-1])
							tmp+=s[i];
					}	
					else
					{
						tmp+=s[i-1];
						break;
					}
				}
			}
			string tmp2=tmp;
			reverse(tmp.begin(),tmp.end());
			cout<<(f==1?tmp2:tmp2+tmp)<<endl;
		}
	}
	return 0;
}

ps:本人实力较菜,只能做出这些简单题,后面的题如果有哪位大神可以解决可以私信我,如果这里面有讲的不清楚或者有错误的,望及时指出! 

举报

相关推荐

2022寒假day1

C++寒假学习DAY1

#day1

day1 markdown

HTML(day1)

0 条评论