题意
再给定的串中找到一个子串,符合:
1.对应的数字不能被二整除;
2.各位之和能被二整除;
思路
符合条件的数最后一位必然是奇数才能不被二整除;
除了最后一位必然还有一个奇数各位之和才能被二整除;
所以可以找到串中两个奇数按顺序输出就可以了;
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int main()
{
string s;
int t;
while(cin>>t)
{
while(t--)
{
int n;
long long sum=0;
int a=-1,b=-1;
cin>>n;
cin>>s;
for(int i=0;i<n;i++)
{
if(a==-1)
{
if((s[i]-'0')%2==1)
{
a=s[i]-'0';
}
}
else if(b==-1)
{
if((s[i]-'0')%2==1)
{
b=s[i]-'0';
break;
}
}
}
if(b!=-1)
{
cout<<a<<b<<endl;
}
else
{
cout<<-1<<endl;
}
}
}
return 0;
}