-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathC++.cpp
More file actions
26 lines (23 loc) · 728 Bytes
/
C++.cpp
File metadata and controls
26 lines (23 loc) · 728 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#include <fstream>
#include <iostream>
#include <regex>
int main() {
std::vector<std::string> longest;
std::regex invalid(".*[gkmqvwxzio].*", std::regex_constants::icase);
std::ifstream words("words.txt");
std::string word;
unsigned long wlen = 0, maxlen = 0;
while (!words.eof()) {
getline(words, word);
wlen = word.length();
if (wlen == maxlen && !regex_match(word, invalid)) {
longest.push_back(word);
} else if (wlen > maxlen && !regex_match(word, invalid)) {
longest.clear();
longest.push_back(word);
maxlen = wlen;
}
}
words.close();
for (const auto &l : longest) std::cout << l << std::endl;
}