-
Notifications
You must be signed in to change notification settings - Fork 0
/
baconeggsandspam.cpp
69 lines (57 loc) · 1.42 KB
/
baconeggsandspam.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
/**
* @file baconeggsandspam.cpp
* @author William Weston
* @brief Bacon, Eggs, and Spam Problem From Kattis
* @version 0.1
* @date 2023-07-31
*
* @copyright Copyright (c) 2023
*
* Source: https://open.kattis.com/problems/baconeggsandspam
*/
#include <cstdlib>
#include <iostream>
#include <limits>
#include <map>
#include <set>
#include <sstream>
#include <string>
#include <vector>
auto print( std::map<std::string, std::set<std::string>> const& data ) -> void;
auto main() -> int
{
for ( int n; std::cin >> n; )
{
if ( n == 0 )
break;
std::cin.ignore( std::numeric_limits<std::streamsize>::max(), '\n' );
auto data = std::map<std::string, std::set<std::string>>();
while ( n-- )
{
auto line = std::string();
std::getline( std::cin, line );
auto iss = std::istringstream( line );
auto name = std::string();
iss >> name;
for ( auto menu_item = std::string(); iss >> menu_item; )
{
data[menu_item].insert( name );
}
}
print( data );
}
return EXIT_SUCCESS;
}
auto print( std::map<std::string, std::set<std::string>> const& data ) -> void
{
for ( auto const& [item, customers] : data )
{
std::cout << item << ' ';
for ( auto const& name : customers )
{
std::cout << name << ' ';
}
std::cout << '\n';
}
std::cout << '\n';
}