sicily 1765
来源:互联网 发布:python 马科维兹模型 编辑:程序博客网 时间:2024/06/04 01:37
#include "iostream"#include "string"#include "algorithm"#include "cmath"using namespace std;bool is_primer(int n)//判断是否为质数{if (n == 1) return false;int m = floor(sqrt(double (n)) + 0.5);for (int i = 2; i <= m; i++)if (n % i == 0)return false;return true;}int main(){string str;while (cin >> str){int size = str.size();int count[26] = {0};for (int i = 0; i < size; i++)//对输入的单词的每一个字母进行判断,计算出现的次数{switch(str[i]){case 'a': count[0]++;break;case 'b': count[1]++;break;case 'c': count[2]++;break;case 'd': count[3]++;break;case 'e': count[4]++;break;case 'f': count[5]++;break;case 'g': count[6]++;break;case 'h': count[7]++;break;case 'i': count[8]++;break;case 'j': count[9]++;break;case 'k': count[10]++;break;case 'l': count[11]++;break;case 'm': count[12]++;break;case 'n': count[13]++;break;case 'o': count[14]++;break;case 'p': count[15]++;break;case 'q': count[16]++;break;case 'r': count[17]++;break;case 's': count[18]++;break;case 't': count[19]++;break;case 'u': count[20]++;break;case 'v': count[21]++;break;case 'w': count[22]++;break;case 'x': count[23]++;break;case 'y': count[24]++;break;case 'z': count[25]++;break;}}sort(count, count+26);//将数组进行排序int maxn, minn;maxn = count[25];for (int i = 0; i < 26; i++)if (count[i] != 0){minn = count[i];break;}int differ = maxn - minn;if (differ > 0){if (is_primer(differ))cout << "Lucky Word" << endl << differ << endl;elsecout << "No Answer" << endl << 0 << endl;}else if (differ == 0)cout << "No Answer" << endl << 0 << endl;}}