-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathevenbutnoteven.cpp
More file actions
78 lines (76 loc) · 1.53 KB
/
evenbutnoteven.cpp
File metadata and controls
78 lines (76 loc) · 1.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#include<bits/stdc++.h>
using namespace std;
// https://codeforces.com/contest/1291/problem/A
typedef long long ll;
ll sumODigits(string a)
{
ll ans=0;
while(!a.empty())
{
int n=a[0]-'0';
ans+=n;
a=a.substr(1);
}
return ans;
}
bool isEbne(string ebne)
{
int dig=ebne[ebne.length()-1]-'0';
ll sum=sumODigits(ebne);
if(dig%2!=0 && sum%2==0)
{
return true;
}
return false;
}
int main()
{
int t;
cin>>t;
while(t--)
{
int n;
cin>>n;
string ebne;
cin>>ebne;
check:
if(isEbne(ebne))
{
cout<<ebne<<endl;
continue;
}
int dig=ebne[ebne.length()-1]-'0';
while(dig%2==0)
{
ebne=ebne.substr(0,ebne.length()-1);
if(ebne.empty())
{
break;
}
dig=ebne[ebne.length()-1]-'0';
}
ll sum=sumODigits(ebne);
if(sum%2!=0)
{
for(int i=0;i<ebne.length();i++)
{
int curr=ebne[i]-'0';
if(curr%2!=0)
{
if(i==0 && ebne[1]=='0')
{
continue;
}
ebne=ebne.substr(0,i)+ebne.substr(i+1);
break;
}
}
}
sum=sumODigits(ebne);
if(ebne.empty() or sum%2!=0)
cout<<-1<<endl;
else
goto check;
}
return 0;
}