A. Even But Not Even
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
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 →→ 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≤t≤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≤n≤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
Copy
4 4 1227 1 0 6 177013 24 222373204424185217171912
output
Copy
1227 -1 17703 2237344218521717191
题意:t组数据,每组输入n位数,通过删除数字使得原来的n位数本身不能被2整除,但是各数位相加可以被2整除。
思路:输出的数可以不用含偶数位,只需输出俩位奇数位,或则偶数位奇数位,考虑到贪心,2位即可
code:
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int a[10];
int main()
{
int t;
scanf("%d",&t);
while(t--){
int n;
string s;
scanf("%d",&n);
cin>>s;//sting类型不推荐使用scanf
int k=0;
for(int i=0;i<n;i++){
if(k==2) break;
if((s[i]-'0')%2==1){
a[k]=s[i]-'0';
k++;
}
}
if(k==2)
printf("%d%d\n",a[0],a[1]);
else
printf("-1\n");
}
return 0;
}