===== C++ 17 =====
#include <iostream>
using namespace std;
int digitOddMax(long n)
{
n = abs(n);
int r = -1;
while(n > 0)
int d = n % 10;
if((d > r) && (d % 2 == 0))
r = d;
n /= 10;
}
return r;
int main()
int n;
cin >> n;
int a[n];
long m;
for(int i = 0; i < n; i++)
cin >> m;
a[i] = digitOddMax(m);
cout << a[i] << " ";
cout << endl;
return 0;
Copyright © 2024 SCHOLAR.TIPS - All rights reserved.
Answers & Comments
===== C++ 17 =====
#include <iostream>
using namespace std;
int digitOddMax(long n)
{
n = abs(n);
int r = -1;
while(n > 0)
{
int d = n % 10;
if((d > r) && (d % 2 == 0))
r = d;
n /= 10;
}
return r;
}
int main()
{
int n;
cin >> n;
int a[n];
long m;
for(int i = 0; i < n; i++)
{
cin >> m;
a[i] = digitOddMax(m);
}
for(int i = 0; i < n; i++)
cout << a[i] << " ";
cout << endl;
return 0;
}
Хотя по сути должно выводить 4 6 8