백준 25192 c++

magicdrill·2024년 4월 17일

백준 문제풀이

목록 보기
318/675

백준 25192 c++

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>

using namespace std;

int input(int lower, int upper);
void input_name(vector <string>& name, int size);
int count_gomgomticon(vector <string> name);

int main(void)
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);

	int N;
	vector <string> name;
	
	N = input(1, 100000);
	input_name(name, N);
	cout << count_gomgomticon(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_name(vector <string> &name ,int size)
{
	//cout << "input_name()" << endl;
	int i;
	string temp;

	for (i = 0; i < size; i++)
	{
		cin >> temp;
		if (i == 0)
		{
			if (temp == "ENTER")
			{
				name.push_back(temp);
			}
			else
			{
				i--;
			}
		}
		else
		{
			if (temp.length() >= 1 && temp.length() <= 20)
			{
				name.push_back(temp);
			}
			else
			{
				i--;
			}
		}
	}

	return;
}

int count_gomgomticon(vector <string> name)
{
	//cout << "count_gomgomticon()" << endl;
	int i, count = 0;
	int size = name.size();
	//vector <string> temp;
	map <string, bool> temp;
	string temp_str;

	for (i = 0; i < size; i++)
	{
		temp_str = name[i];
		if (temp_str == "ENTER")//만약 ENTER인 경우
		{
			temp.clear();
		}
		else// ENTER가 아닌 경우
		{
			//find함수 결과는 인덱스, 못찾으면 end()값 
			if (temp.find(temp_str) == temp.end())//temp에서 name[i]값 탐색
			{
				temp.emplace(temp_str, true);
				count++;
			}
			else
			{
				;
			}
		}
	}

	return count;
}

0개의 댓글