Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <set>
- #include <limits>
- using namespace std;
- char minEvenAsciiIntersection(const set<char>& A, const set<char>& B) {
- int minEvenAscii = numeric_limits<int>::max();
- int minAscii = numeric_limits<int>::max();
- bool evenFound = false;
- for (char elem : A) {
- if (B.find(elem) != B.end()) { // Проверка дали елементът се среща и в двете множества
- int asciiValue = static_cast<int>(elem);
- if (asciiValue % 2 == 0) { // Проверка за четност
- evenFound = true;
- if (asciiValue < minEvenAscii) {
- minEvenAscii = asciiValue;
- }
- }
- if (asciiValue < minAscii) {
- minAscii = asciiValue;
- }
- }
- }
- if (evenFound) {
- return static_cast<char>(minEvenAscii);
- }
- else {
- return static_cast<char>(minAscii);
- }
- }
- int main() {
- set<char> A = { 'e', 'r', 'D', 'U', 'w', 'd', 'B', 'x', 'N', 'z' };
- set<char> B = { 'm', 'd', 'r', 'D', 'l', 'w', 'А', 'W'};
- char result = minEvenAsciiIntersection(A, B);
- cout << "The result is: " << result << std::endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement