2008年NOIP全国联赛提高组
题目描述 Description
思路
很水的移动字符串处理,读入找大小。需要注意的是空格和最小值是零的情况。
var a:array['A'..'z'] of longint; s:ansistring; i,max,min:longint; j:char; function p(x:longint):boolean; var i:longint; begin if (x=1)or(x=0)or(x<0) then exit(false); for i:=2 to trunc(sqrt(x)) do if (x mod i=0) then exit(false); exit(true); end; begin fillchar(a,sizeof(a),0); readln(s); for i:=1 to length(s) do begin if s[i]=' ' then continue; inc(a[s[i]]); end; max:=0;min:=maxlongint; for j:='A' to 'z' do begin if a[j]>max then max:=a[j]; if (a[j]<min)and(a[j]<>0) then min:=a[j]; end; if p(max-min) then begin writeln('Lucky Word'); writeln(max-min); end else begin writeln('No Answer'); writeln(0); end; end.