codeforces round #616 div2 A (Even but not even)水题

水题:

链接:https://codeforces.com/contest/1291/problem/A

题意:给一个字符数组,删去数组中的一些数,使得剩下的数字的和为偶数,其中的数字有偶数多个奇数且首尾数字为奇数

找两个奇数就满足题意了:

代码:

#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
using namespace std;
#define maxx 1010
const int maxn=3e5+10;
int n;
int main()
{
    int t;
    scanf("%d",&t);
    while(t--)
    {
    scanf("%d",&n);
    char s[maxn];
    scanf("%s",s);
    string ch="";
    int flag=0;
    for(int i=0; i<n; i++)
    {
        if((s[i]-'0')&1)
            ch+=s[i];
        if(ch.size()>=2)
        {
            flag=1;
            break;
        }
    }
    if(flag)
        cout<<ch<<endl;
    else printf("-1\n");
    }
    return 0;}

猜你喜欢

转载自www.cnblogs.com/sweetlittlebaby/p/12661437.html
今日推荐