Answer the question
In order to leave comments, you need to log in
Answer the question
In order to leave comments, you need to log in
Alas, this is the only way it works (for the general case of strings). If you can use stl, use std::map like this
std::vector<std::map<char, size_t>> maps(strings.size());
size_t nmax = 0;
size_t fmax = 0;
for(size_t i=0;i<strings.size();++i)
{
for(const auto& j:strings[i])
{
const size_t current = ++maps[i][j];
if(current>fmax)
{
fmax=current;
nmax=i;
}
}
}
//теперь в nmax у нас номер строки с максимально частым повторением
std::vector<int> row = ...;
std::unordered_map<int, size_t> counts;
for (int x : row) ++counts[x];
size_t n_duplicates = row.size();
for (auto p : counts) {
if (p.second == 1) --n_duplicates;
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question