(알고리즘) 문자열 비교

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

using namespace std;

struct cmp {
bool operator() (const char* a, const char* b) const {
return strcmp(a, b) < 0;
}
};

int main()
{
FILE *empty; freopen_s(&empty,"ee.txt", "r", stdin);
char str[5001];
cin >> str;
vector<char*> suffix;
int len = strlen(str);
for (int i = 0; i<len; i++) {
suffix.push_back(str + i);
}
sort(suffix.begin(), suffix.end(), cmp());
int max = 0;
for (int i = 0; i<suffix.size() - 1; i++) {
int k = 0;
while (suffix[i][k] == suffix[i + 1][k]) k++;
max = std::max(max, k);
}
printf("%d\n", max);
return 0;
}

댓글

이 블로그의 인기 게시물

(네트워크)폴링방식 vs 롱 폴링방식

(ElasticSearch) 결과에서 순서 정렬

(18장) WebSocekt과 STOMP를 사용하여 메시징하기