天天看點

笨小猴(answer拼錯了 弄了半天)

題目:

笨小猴(answer拼錯了 弄了半天)

代碼:

#include<stdio.h>

#include<string.h>

//判斷是不是質數 如果是 就傳回1 不是就傳回0 。注意0和1也不是質數要區分開

int if_zhi(int n) {

if (n == 1 || n == 0) {

return 0;

}

else {

for (int i = 2; i <= n/2; i++) {

if (n % i == 0) {

return 0;

}

}

return 1;

}

}

int main() {

char a[100];

scanf_s("%s", a, 100);//輸入字元串

int count[26] = { 0 };//建立一共26個字母對應的記錄數字的數組

for (int i = 0; a[i]!='\0'; i++) {

count[a[i] - 95]++;//出現一次 對應的就加

}

int min = 101;

int max = -1;

for (int i = 0; i < 26; i++) {

//分别找出最大 最小值

if (count[i] > max) {

max = count[i];

}

if (count[i]>0&&count[i]<min) {//最小值非0的(很重要)

min = count[i];

}

}

//printf("%d %d", max, min);

int result = max - min;

if (if_zhi(result)) {

printf("Lucky Word\n%d", result);

}

else {

printf("No Answer\n0");

}

return 0;

}

繼續閱讀