题目链接
/*
Name:hdu-2609-How many
Copyright:
Author:
Date: 2018/4/24 15:47:49
Description:
串的最小表示
求出每个串的最小表示,用set去重
*/
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <set>
using namespace std;
string smallestRepresation (string s) {
int i, j ,k ,l;
int N = s.length();
s += s;
for (i=, j=; j<N;) {
for (k=; k<N && s[i+k] == s[j+k]; k++) ;
if (k >=N ){
break;
}
if (s[i+k] <s[j+k]) {
j += k+;
} else {
l = i + k;
i = j;
j = max(l ,j) + ;
}
}
return s.substr(i, N);
}
int main()
{
int n;
set<string> capt;
while (cin>>n) {
string str;
capt.clear();
for (int i=; i<n; i++) {
cin>>str;
capt.insert(smallestRepresation(str));
}
cout<<capt.size()<<endl;
}
return ;
}