笨小猴pascal题解
题意
找出在单词里出现最多的单词的次数,再找出在单词里出现最少的单词的次数,最多和最少的次数相减,如果结果是素数,
那么就是Lucky Word,不然就是No Answer
分析
假设maxn是单词中出现次数最多的字母的出现次数,minn是单词中出现次数最少的字母的出现次数,如果maxn-minn是一个质数,那么笨小猴就认为这是个Lucky
Word
var
w:string;
a:array[0..200]of longint;
l,maxn,minn,i,j,t,m:longint;
function ss(s:longint):longint;
var
bz,i:longint;
begin
bz:=1;
for i:=2 to trunc(sqrt(s)) do
if s mod i=0 then
begin
bz:=0;
break;
end;
exit(bz);
end;
begin
read(w);
l:=length(w);
fillchar(a,sizeof(a),0);
maxn:=0;
minn:=100;
for i:=1 to l do
begin
if a[ord(w[i])]=0 then
begin
for j:=pos(w[i],w) to l do
if w[j]=w[i] then a[ord(w[i])]:=a[ord(w[i])]+1;
if a[ord(w[i])]>=maxn then maxn:=a[ord(w[i])];
if a[ord(w[i])]<=minn then minn:=a[ord(w[i])];
end;
end;
t:=ss(maxn-minn);
m:=maxn-minn;
if (t=1)and(m>=2) then
begin
writeln('Lucky Word');
write(m);
end else
if t<=1 then
begin
writeln('No Answer');
write(0);
end;
end.