CodeFoeces-672B

题目

原题链接:B. Different is Good

题意

有n个字符,问需要改变几个字符使所有字符不相同。
若不相同的大于没出现过的,则必定做不到。

代码

#include
using namespace std;
int main() {
    int l,s[26]={0},ans=0,tmp=0;
    char t;
    cin>>l;
    for(int i=0;i>t;
        s[t-'a']++;
    }
    for(int i=0;i<26;i++){
        if(s[i]>1) ans+=s[i]-1;
        if(s[i]==0) tmp++;
    }
    printf("%d\n",ans>tmp?-1:ans);
    return 0;
}

你可能感兴趣的:(CodeFoeces-672B)