NOIP2008笨小猴
NOIP2008提高组第一题,没什么说的。。没事闲的再打一遍。
program p1495;
var
s:string;
i,max,min:longint;
ch:char;
count:array['a'..'z'] of longint;
used:array['a'..'z'] of boolean;
procedure prime(x:longint);
var
i:longint;
p:boolean; //质数否
begin
if (x=1) or (x=0) then
begin
writeln('No Answer');
writeln(0);
halt;
end;
p:=true;
for i:=2 to trunc(sqrt(x)) do if x mod i=0 then
begin
p:=false;
break;
end;
if p then
begin
writeln('Lucky Word');
writeln(x);
end else
begin
writeln('No Answer');
writeln(0);
end;
end;
begin
fillchar(count,sizeof(count),0);
readln(s);
for i:=1 to length(s) do
begin
inc(count[s[i]]);
used[s[i]]:=true;
end;
max:=0;
min:=maxint;
for ch:='a' to 'z' do
begin
if not used[ch] then continue;
if count[ch]>max then max:=count[ch];
if count[ch]<min then min:=count[ch];
end;
prime(max-min);
end.
comments powered by Disqus