labs-edaf30/lab2/word.cc

35 lines
799 B
C++
Raw Normal View History

2024-11-20 17:46:21 +01:00
#include "word.h"
#include <algorithm>
2021-10-27 15:15:47 +02:00
#include <string>
#include <vector>
using std::string;
2024-11-20 17:46:21 +01:00
using std::vector;
Word::Word(const string &w, const vector<string> &t) : word(w), triagrams(t) {
std::sort(triagrams.begin(), triagrams.end());
}
string Word::get_word() const { return string(); }
2021-10-27 15:15:47 +02:00
2024-11-20 17:46:21 +01:00
unsigned int Word::get_matches(const vector<string> &t) const {
unsigned int matches = 0;
2021-10-27 15:15:47 +02:00
2024-11-20 17:46:21 +01:00
for (const auto &triagram : t) {
if (std::binary_search(triagrams.begin(), triagrams.end(), triagram)) {
++matches;
}
}
return matches;
2021-10-27 15:15:47 +02:00
}
2024-11-20 17:46:21 +01:00
std::ostream &operator<<(std::ostream &out, const Word &w) {
auto space = string(" ");
out << w.word;
out << space;
for (const auto &tria : w.triagrams) {
out << space << tria;
}
return out;
2021-10-27 15:15:47 +02:00
}