您的位置:首页 > Web前端

【CodeForces 672B】Different is Good

2016-07-31 16:28 288 查看


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

因为只能是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);
}
}


  
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: