Codeforces Round #616 (Div. 2)A. Even But Not Even
程序员文章站
2022-06-08 12:26:23
...
A. Even But Not Even
题目链接-Even But Not Even
题目大意
给你一个长整数,可以删减里面的任意数字(也可以不删减),要求本身不能除以2,但是该数的各位和能除以2,输出任意符合要求的数
解题思路
贪心,输出一个两位数,每位数字都是奇数即可,即在原来长整数找到两个奇数(ps:不能改变原来数字顺序),否则输出-1
附上代码
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int INF=0x3f3f3f;
typedef pair<int,int> PII;
string s;
int a[5];
int main(){
ios::sync_with_stdio(0);
cin.tie(0);cout.tie(0);
int t;
cin>>t;
while(t--){
int n;
cin>>n;
cin>>s;
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)
cout<<a[0]<<a[1]<<endl;
else
cout<<"-1"<<endl;
}
return 0;
}
上一篇: 组合数
推荐阅读
-
Codeforces Round #655 (Div. 2) A. Omkar and Completion
-
Codeforces Round #659 (Div. 2) A. Common Prefixes(字符串,思维)
-
Codeforces Round #650 (Div. 3) B. Even Array
-
A. Add Odd or Subtract Even(思维题) Codeforces Round #624 (Div. 3)
-
Educational Codeforces Round 93 (Rated for Div. 2) A. Bad Triangle
-
Codeforces Round #664 (Div. 2) A. Boboniu Likes to Color Balls
-
Codeforces Round #156 (Div. 2)-A. Greg's Workout_html/css_WEB-ITnose
-
Codeforces Round #107 (Div. 2)-A. Soft Drinking_html/css_WEB-ITnose
-
Codeforces Round #191 (Div. 2)-A. Flipping Game_html/css_WEB-ITnose
-
Codeforces Beta Round #75 (Div. 2)-A. Chips_html/css_WEB-ITnose