lanqiao/数组偶数最小值.c
2024-11-24 15:33:02 +08:00

46 lines
1.2 KiB
C
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// 【问题描述】
// 小蓝有一个数组 a[1], a[2], ..., a[n] ,请求出数组中值最小的偶数,输出这个值。
// 【输入格式】
// 输入的第一行包含一个整数 n 。
// 第二行包含 n 个整数,相邻数之间使用一个空格分隔,依次表示 a[1], a[2], ..., a[n] 。
// 【输出格式】
// 输出一行,包含一个整数,表示答案。数据保证数组中至少有一个偶数。
// 【样例输入】
// 9
// 9 9 8 2 4 4 3 5 3
// 【样例输出】
// 2
// 【样例输入】
// 5
// 4321 2143 1324 1243 4312
// 【样例输出】
// 1324
// 【评测用例规模与约定】
// 对于 30% 的评测用例1 <= n <= 1000 <= a[i] <= 1000。
// 对于 60% 的评测用例1 <= n <= 10000 <= a[i] <= 1000。
// 对于所有评测用例1 <= n <= 100000 <= a[i] <= 1000000。
#include <stdio.h>
int main() {
int n;
scanf("%d", &n);
int a[n];
for(int i = 0; i < n; i++) {
scanf("%d", &a[i]);
}
int min_even = 1000001;
for(int i = 0; i < n; i++) {
if(a[i] % 2 == 0 && a[i] < min_even) {
min_even = a[i];
}
}
printf("%d\n", min_even);
return 0;
}