vector unique (trie)

황연준·2024년 2월 29일
0
#include <iostream>
#include <algorithm>
#include <queue>
#include <vector>
#include <cstring>

using namespace std;

int num, cnt, flag;
string str;

int main(void) {

	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);

	int tc;
	cin >> tc;

	for (int t = 1; t <= tc; t++) {

		cin >> num >> str;

		vector<string> v;

		for (int i = 0; i < str.length(); i++) {
			for (int j = 1; j <= str.length() - i; j++) {
				string sub_str = str.substr(i, j); //substr(위치, 크기)
				v.push_back(sub_str);
			}
		}

		sort(v.begin(), v.end());
		v.erase(unique(v.begin(), v.end()), v.end()); // 중복제거(sort랑 세트로 써야함)

		//cout << v.size() << "\n";
		if (num > v.size()) { cout << "#" << t << " none" << "\n"; }
		else { cout << "#" << t << " " << v[num - 1] << "\n"; }

	}


	return 0;
}
profile
서강대💻

0개의 댓글