Find words whose first and last three letters are equal: Difference between revisions
Content added Content deleted
(add freebasic) |
(Added C++ solution) |
||
Line 29: | Line 29: | ||
tartar |
tartar |
||
testes |
testes |
||
</pre> |
|||
=={{header|C++}}== |
|||
<lang cpp>#include <cstdlib> |
|||
#include <fstream> |
|||
#include <iostream> |
|||
int main(int argc, char** argv) { |
|||
const char* filename(argc < 2 ? "unixdict.txt" : argv[1]); |
|||
std::ifstream in(filename); |
|||
if (!in) { |
|||
std::cerr << "Cannot open file '" << filename << "'.\n"; |
|||
return EXIT_FAILURE; |
|||
} |
|||
std::string word; |
|||
int n = 0; |
|||
while (getline(in, word)) { |
|||
const size_t len = word.size(); |
|||
if (len > 5 && word.compare(0, 3, word, len - 3) == 0) |
|||
std::cout << ++n << ": " << word << '\n'; |
|||
} |
|||
return EXIT_SUCCESS; |
|||
}</lang> |
|||
{{out}} |
|||
<pre> |
|||
1. antiperspirant |
|||
2. calendrical |
|||
3. einstein |
|||
4. hotshot |
|||
5. murmur |
|||
6. oshkosh |
|||
7. tartar |
|||
8. testes |
|||
</pre> |
</pre> |
||