Recognition

DD now has a string of length n, DD that if all substrings of length x and do not repeat, the x value is recognized, he wants to know the minimum value is the number of identifiable

The input format
of the first row represents an integer n

The second line of a character string length n

Output format
minimum value of the output xx

Data range
for 30% of the data, 1≤n≤10

For 60% of the data, 1≤n≤100

To 100% of the data, 1≤n≤1000

Extra spaces at the end of each row, the answer does not affect the validity of the output

Sample input copy
. 6
xyzxyz
sample output copy
4

#include<bits/stdc++.h>
using namespace std;
#define N 10005
int n, lens;
string s, tmp[1005];
bool cmp(int x){//找出所有长度为x的字符串
	int k = 0;
	for(int i=1; i<=lens; ++i)//所有字符串清空
		tmp[i] = "";
	for(int i=0; i<lens; ++i){//每一个字符串的开始下标
		++k;
		if(x+i <= lens){
			for(int p=i; p<x+i; p++)//每个字符串的形成
				tmp[k] += s[p];
		}else
			break;
	}
	sort(tmp+1, tmp+k+1);
	for(int i=1; i<=k; ++i){//判断是否有相等字符串
		if(tmp[i] == tmp[i+1])
			return false;
	}	
	return true;
}
int main(){ 
	scanf("%d", &n);
	cin >> s;
	lens = s.size();
	for(int j=1; j<=lens; ++j){
		if(cmp(j)){
			cout << j;
			break;
		}
	}
	return 0;
}
Published 43 original articles · won praise 23 · views 2527

Guess you like

Origin blog.csdn.net/qq_39053800/article/details/104335235