[BOJ] Cubeditor

Date:

[BOJ] Cubeditor

Problem URL : Cubeditor

#include <iostream>
#include <algorithm>
#include <set>
#include <string>
using namespace std;

int ans, cnt;
string word;
set<string> strings;

int main() {
	ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
	cin >> word;
	int length = word.length();
	for (int i = 0; i < length; ++i) {
		strings.insert(word);
		word = word.substr(1);
	}
	string pre = "";
	for (const auto &str : strings) {
		cnt = 0;
		while (pre[cnt] == str[cnt]) ++cnt;
		ans = max(ans, cnt);
		pre = str;
	}
	cout << ans;

	return 0;
}

댓글