解题思路:
统计并判断(max-min)差是否为质数
质素依旧打表
注意事项:
字母不存在的不算hhh
参考代码:
#include <stdio.h> int main() { int ch; int n[26] = {0}; int max = 1, min = 100; int ans[15] = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47}; int i; do { ch = getchar(); n[ch - 'a']++; } while (ch != '\n'); for (i = 0; i < 26; i++) { if (n[i] == 0) continue; if (max < n[i]) max = n[i]; if (min > n[i]) min = n[i]; } for (i = 0; i < 15; i++) { if (ans[i] == max - min) { printf("Lucky Word\n%d\n", max - min); break; } } if (i == 15) { printf("No Answer\n0\n"); } return 0; }
0.0分
8 人评分