码迷,mamicode.com
首页 > 其他好文 > 详细

【CodeForces 672B】Different is Good

时间:2016-07-31 17:42:45      阅读:178      评论:0      收藏:0      [点我收藏+]

标签:

字符串所有子串要不同。求修改最少多少个字符。

因为只能是26个字母,显然大于26的不可能有答案,其它情况ans+=u[i]-1;u[i]是字母出现的次数。

#include<cstdio>
char s;
int n,u[30],ans;
int main(){
	scanf("%d ",&n);
	for(int i=0;i<n;i++){
		scanf("%c ",&s);
		u[s-‘a‘]++;
	}
	if(n>26)printf("-1");
	else{
		for(int i=0;i<26;i++)
			if(u[i])ans+=u[i]-1;
		 printf("%d",ans);
	}
}

  

【CodeForces 672B】Different is Good

标签:

原文地址:http://www.cnblogs.com/flipped/p/5723302.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!