0% found this document useful (0 votes)
19 views1 page

Output Code

The provided C++ program reads a numeric input representing a cow ID and matches it against names in a dictionary file. Each digit corresponds to a set of characters, and the program checks if any name in the dictionary can be formed using the characters associated with the digits of the cow ID. If a match is found, the name is printed to the console.

Uploaded by

potatopixelpie
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views1 page

Output Code

The provided C++ program reads a numeric input representing a cow ID and matches it against names in a dictionary file. Each digit corresponds to a set of characters, and the program checks if any name in the dictionary can be formed using the characters associated with the digits of the cow ID. If a match is found, the name is printed to the console.

Uploaded by

potatopixelpie
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

#include <iostream>

#include <fstream>
#include <vector>
#include <string>

int main() {
std::ifstream paindictionary("[Link]");
std::string cowid;
std::cin >> cowid;
std::vector<std::vector<char>> nums = {
{},
{'A', 'B', 'C'},
{'D', 'E', 'F'},
{'G', 'H', 'I'},
{'J', 'K', 'L'},
{'M', 'N', 'O'},
{'P', 'R', 'S'},
{'T', 'U', 'V'},
{'W', 'X', 'Y'}
};
std::vector<std::vector<char>> p;

for (char char_id : cowid) {


p.push_back(nums[char_id - '0']);
}

std::string name;
while (std::getline(paindictionary, name)) {
if ([Link]() == [Link]()) {
bool flag = true;
for (size_t i = 0; i < [Link](); ++i) {
if (std::find(p[i].begin(), p[i].end(), name[i]) == p[i].end()) {
flag = false;
break;
}
}
if (flag) {
std::cout << name << std::endl;
}
}
}

return 0;
}

You might also like