-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcompoundwords.cpp
70 lines (57 loc) · 1.63 KB
/
compoundwords.cpp
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
/**
* @file compoundwords.cpp
* @author William Weston
* @brief Compound Words
* @version 0.1
* @date 2023-07-31
*
* @copyright Copyright (c) 2023
*
* Source: https://open.kattis.com/problems/compoundwords
*/
#include <cstdlib>
#include <iostream>
#include <set>
#include <string>
#include <utility>
#include <vector>
auto load_word_list() -> std::vector<std::string>;
auto generate_compounds( std::vector<std::string> const& data ) -> std::set<std::string>;
auto print( std::set<std::string> const& list ) -> void;
auto main() -> int
{
auto const word_list = load_word_list();
auto const compound_words = generate_compounds( word_list );
print( compound_words );
return EXIT_SUCCESS;
}
auto load_word_list() -> std::vector<std::string>
{
auto word_list = std::vector<std::string>();
for ( auto word = std::string(); std::cin >> word; )
{
word_list.push_back( std::move( word ) );
}
return word_list;
}
auto generate_compounds( std::vector<std::string> const& data ) -> std::set<std::string>
{
auto compound_words = std::set<std::string>();
auto const end = data.end();
for ( auto begin = data.begin(); begin != end; ++begin )
{
for ( auto first = data.begin(); first != end; ++first )
{
if ( begin == first )
continue;
auto tmp = *begin + *first;
compound_words.insert( std::move( tmp ) );
}
}
return compound_words;
}
auto print( std::set<std::string> const& list ) -> void
{
for ( auto const& word : list )
std::cout << word << '\n';
}