48 lines
868 B
C
48 lines
868 B
C
#include <stdio.h>
|
||
|
||
#define MAXLEN 110
|
||
|
||
int isPrime(int n); //判断一个整数是否是质数,是则返回1,否则返回0
|
||
int getResult(char word[]);
|
||
|
||
int main() {
|
||
char word[MAXLEN];
|
||
|
||
scanf("%s", word);
|
||
printf("%d\n", getResult(word));
|
||
|
||
return 0;
|
||
}
|
||
|
||
/* 请在这里填写答案 */
|
||
int getResult(char word[]) {
|
||
int hashtable[26] = {};
|
||
|
||
// Load word into hash table
|
||
for (int i = 0; word[i] != '\0'; i++) {
|
||
hashtable[word[i] - 'a']++;
|
||
}
|
||
|
||
// Analyze words
|
||
int max = 0;
|
||
int min = MAXLEN;
|
||
for (int i = 0; i < 26; i++) {
|
||
// If hashtable[i] == 0, the letter is not in the word.
|
||
if (hashtable[i] == 0) {
|
||
continue;
|
||
}
|
||
if (hashtable[i] > max) {
|
||
max = hashtable[i];
|
||
}
|
||
if (hashtable[i] < min) {
|
||
min = hashtable[i];
|
||
}
|
||
}
|
||
|
||
if (isPrime(max - min)) {
|
||
return max - min;
|
||
} else {
|
||
return -1;
|
||
}
|
||
}
|