Even But Not Even

Let's define a number ebne (even but not even) if and only if its sum of digits is divisible by 22 but the number itself is not divisible by 22. For example, 1313, 12271227, 185217185217 are ebne numbers, while 1212, 22, 177013177013, 265918265918 are not. If you're still unsure what ebne numbers are, you can look at the sample notes for more clarification.

You are given a non-negative integer ss, consisting of nn digits. You can delete some digits (they are not necessary consecutive/successive) to make the given number ebne. You cannot change the order of the digits, that is, after deleting the digits the remaining digits collapse. The resulting number shouldn't contain leading zeros. You can delete any number of digits between 00 (do not delete any digits at all) and n-1n−1.

For example, if you are given s=s=222373204424185217171912 then one of possible ways to make it ebne is: 222373204424185217171912 \rightarrow→ 2237344218521717191. The sum of digits of 2237344218521717191 is equal to 7070 and is divisible by 22, but number itself is not divisible by 22: it means that the resulting number is ebne.

Find any resulting number that is ebne. If it's impossible to create an ebne number from the given number report about it.

Input

The input consists of multiple test cases. The first line contains a single integer tt (1 \le t \le 10001≤t≤1000)  — the number of test cases. The description of the test cases follows.

The first line of each test case contains a single integer nn (1 \le n \le 30001≤n≤3000)  — the number of digits in the original number.

The second line of each test case contains a non-negative integer number ss, consisting of nn digits.

It is guaranteed that ss does not contain leading zeros and the sum of nn over all test cases does not exceed 30003000.

Output

For each test case given in the input print the answer in the following format:

  • If it is impossible to create an ebne number, print "-1" (without quotes);
  • Otherwise, print the resulting number after deleting some, possibly zero, but not all digits. This number should be ebne. If there are multiple answers, you can print any of them. Note that answers with leading zeros or empty strings are not accepted. It's not necessary to minimize or maximize the number of deleted digits.
  • Example

    Input

    4
    4
    1227
    1
    0
    6
    177013
    24
    222373204424185217171912
    

    Output

    1227
    -1
    17703
    2237344218521717191
  • 题意:给一串数字 ,可以删除数字中的数,让它变为奇数且数字各个位数的和为偶数。
  • 由小学二年级知识可知(奇数+奇数=偶数)。所以我们可以把数字中的偶数项全消去。
  • 然后把各个位数的奇数的个数变为偶数。就能得到满足题意的一串数字了。
  • #include<iostream>
    using namespace std;
    int main()
    {
    	int t,biao;
    	char a[10000];
    	cin>>t;
    	while(t--)
    	{
    		int n,k=0,biao;
    		cin>>n;
    		cin>>a;
    		for(int i=0;i<=n-1;i++)
    		{
    			if(a[i]%2==0){
    				a[i]='0';
    			}else{
    				k++;
    				biao=i;
    			}
    		}
    	/*	for(int i=0;i<=n-1;i++){
    			cout<<a[i]; 
    		}cout<<endl;
    		cout<<k<<" "<<biao<<endl;*/
    		if(k==0||k==1){
    			cout<<-1<<endl; 
    		}
    		else if(k%2==0){
    			for(int i=0;i<=n-1;i++)
    			{
    				if(a[i]!='0'){
    					cout<<a[i];
    							}	
    			}cout<<endl;
    
    		}else{
    			for(int i=0;i<=n-1;i++){
    				if(a[i]=='0'||i==biao){
    					continue;
    				}else{
    					cout<<a[i];
    				}
    			}cout<<endl;
    	
    		}
    	
    	}
    
     } 

    当它奇数个数为1或0时不满足输出-1;

  • 我标记了最后的奇数。如果奇数个数为奇数那就删去我们标记的这个奇数。

  • 如果为偶数就直接输出。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

我啊fw一个

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值