백준 11478 c++

magicdrill·2024년 4월 3일

백준 문제풀이

목록 보기
255/673

백준 11478 c++

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

using namespace std;

string input_str(int lower, int upper);
int check_sub_string(string S);

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

	int count;
	string S;

	S = input_str(1, 1000);
	count = check_sub_string(S);
	cout << count << "\n";

	return 0;
}

string input_str(int lower, int upper)
{
	string temp;

	while (1)
	{
		cin >> temp;
		if (temp.length() >= lower && temp.length() <= upper)
		{
			break;
		}
		else
		{
			;
		}
	}

	return temp;
}

int check_sub_string(string S)
{
	int count = 0;
	vector <string> sub_str;
	int i, j;

	for (i = 0; i < S.length(); i++)
	{
		for (j = 0; j < S.length() - i; j++)
		{
			//sub_str.push_back(S.substr(j, j+i));
			sub_str.push_back(S.substr(j, i + 1)); // j부터 i+1개 만큼
		}
	}
	sort(sub_str.begin(), sub_str.end());
	sub_str.erase(unique(sub_str.begin(), sub_str.end()), sub_str.end());
	count = sub_str.size();

	return count;
}

0개의 댓글