Наши проекты:
Журнал · Discuz!ML · Wiki · DRKB · Помощь проекту |
||
ПРАВИЛА | FAQ | Помощь | Поиск | Участники | Календарь | Избранное | RSS |
[3.134.81.206] |
|
Страницы: (2) 1 [2] все ( Перейти к последнему сообщению ) |
Сообщ.
#16
,
|
|
|
Сообщ.
#17
,
|
|
|
А они мне отказали. Типа неправильно написал задание. По трём типовым проблемам -
Не работает сразу указанный в задании тест. Не работают другие тесты. Не компилируется под MSVC 2013 (хотя это было в условиях). Вод код, который я им отправил #include <iostream> #include <map> #include <vector> #include <fstream> #include <locale> class CDataBuffer { public: template <typename TFunc> void Parse(const char *data, const char *end, TFunc &&func) { const char *word = nullptr; for (auto psz = data; psz != end; ++psz) { if (std::isalpha(*psz, std::locale::classic())) { if (!word) word = psz; } else if (word) { if (m_data.empty()) func(word, std::distance(word, psz)); else { m_data.insert(m_data.end(), word, psz); func(m_data.data(), m_data.size()); m_data.clear(); } word = nullptr; } else Flush(func); } if (word) m_data.insert(m_data.end(), word, end); } template <typename TFunc> void Flush(TFunc &&func) { if (m_data.empty()) return; func(m_data.data(), m_data.size()); m_data.clear(); } protected: std::vector<char> m_data; }; int main(int argc, char *argv[]) { if (argc < 2) { std::cerr << "Invalid arguments" << std::endl; return -1; } std::ifstream in(argv[1]); static const size_t _sz = 1024; char buf[_sz]; std::map<std::string, size_t> words; CDataBuffer data; auto fn = [&words](const char *psz, size_t sz) { auto it = words.emplace(std::make_pair(std::string(psz, sz), 0)).first; ++it->second; }; while (in.good()) { in.read(buf, _sz); data.Parse(buf, buf + in.gcount(), fn); } data.Flush(fn); std::ofstream fout; if (argc > 2) fout.open(argv[2]); auto &out = fout.is_open()? fout: std::cout; out << "By word:" << std::endl; std::multimap<size_t, const char *> words2; for (auto it = words.begin(), end = words.end(); it != end; ++it) { out << it->first << ", " << it->second << std::endl; words2.emplace(std::make_pair(it->second, it->first.c_str())); } out << std::endl; out << "By count:" << std::endl; for (auto it = words2.rbegin(), end = words2.rend(); it != end; ++it) out << it->first << ", " << it->second << std::endl; return 0; } Что там может не работать или не компилится - я не знаю. Ну и по-барабану, видать не судьба мне научиться программировать на C++ |
Сообщ.
#18
,
|
|
|
А задание какое было?
|
Сообщ.
#19
,
|
|
|
Цитата barazuk @ А задание какое было? Подсчитать количество слов в файле |
Сообщ.
#20
,
|
|
|
меня тоже не взяли сказали слишком умный
|
Сообщ.
#21
,
|
|
|
Че прямо так и сказали?
|
Сообщ.
#22
,
|
|
|
почти, послали к бабушке
|
Сообщ.
#23
,
|
|
|
так, вторая вертикальная вонючая лужа нашлась где же бойцы-то?
|
Сообщ.
#24
,
|
|
|
Цитата _lcf_ @ где же бойцы-то? Да, где настоящие, горизонтальные, лужи? |
Сообщ.
#25
,
|
|
|
Кстати, на днях опубликовали видео всех лекций первого курса.
|
Сообщ.
#26
,
|
|
|
так, ну вы расскажите, сколько бойцов-то удалось найти в этих ваших вонючих лужах?
|