백준 26069 c++
//set으로 다시 한번 풀어보기
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <algorithm>
using namespace std;
int input(int lower, int upper);
void input_names(vector <pair<string, string>>& name, int size);
int dance_count(vector <pair<string, string>> name);
int main(void)
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int N;
vector <pair<string, string>> name;
N = input(1, 1000);
input_names(name, N);
cout << dance_count(name) << "\n";
return 0;
}
int input(int lower, int upper)
{
//cout << "input()" << endl;
int A;
while (1)
{
cin >> A;
if (A >= lower && A <= upper)
{
break;
}
else
{
;
}
}
return A;
}
void input_names(vector <pair<string, string>> &name, int size)
{
//cout << "input_names()" << endl;
int i;
string temp1, temp2;
for (i = 0; i < size; i++)
{
cin >> temp1 >> temp2;
if (temp1.length() <= 20 && temp2.length() <= 20 && temp1 != temp2)
{
name.push_back(make_pair(temp1, temp2));
}
else
{
i--;
}
}
return;
}
int dance_count(vector <pair<string, string>> name)
{
//cout << "dance_count()" << endl;
int count = 1, i;
int size = name.size();
map <string, bool> dance_list;//중복 비허용
string first, second;
dance_list.emplace("ChongChong", true);
for (i = 0; i < size; i++)
{
first = name[i].first;
second = name[i].second;
if (dance_list.find(first) == dance_list.end() && dance_list.find(second) == dance_list.end())//ChongChong을 만난 사람과 만나지 못한 경우
{
;
}
else//ChongChong또는 ChongChong과 만난 사람과 만난 경우//중복 비허용
{
dance_list.emplace(first, true);
dance_list.emplace(second, true);
}
}
count = dance_list.size();
return count;
}