CF621A Wet Shark and Odd and Even(C++)

CF621A Wet Shark and Odd and Even

在这里插入图片描述
题意翻译
输入N个正整数选择其中的几个,组成最大的偶数(如果不选输出0)

输入输出样例
输入:

3
1 2 3

输出:

6

输入:

5
999999999 999999999 999999999 999999999 999999999

输出:

3999999996

就是全部加起来,如果是偶数就直接输出,是奇数就减去输入中那个最小的奇数

#include<iostream>
#include<cstdio>
#include<iomanip>
#include<stack>
#include<queue>
#include<cstdlib>
#include <algorithm>
#include<string.h>
#include<math.h>
#define llu unsigned long long
using namespace std;


int main()
{
    
    
	int n;
	cin >> n ;
	long long a[n+5],b[n+5],sum=0;
	int j=0,k=0;
	for(int i=0;i<n;i++)
	{
    
    
		int x;
		cin >> x ;
		if(x%2==0)a[j++]=x;//我把偶数也存在一个数组里了,这个题其实没必要
		else b[k++]=x;
		sum+=x;
	}
	
	if(sum%2==0)cout << sum << endl ;
	
	else{
    
    
		long long min=0x3f3f3f3f3f3f;
		for(int i=0;i<k;i++)
		{
    
    
			if(b[i]<min)min=b[i];
		}
		sum-=min;
		cout << sum << endl ;
	}

	return 0;
}

猜你喜欢

转载自blog.csdn.net/wangyurenwls/article/details/118656494