您的位置:首页 > 其它

USACO 1.2-Name That Number

2010-06-21 14:00 495 查看
题目

依次读入字典文件中的名字然后判断是否可行,

首先是名字的长度,然后依次判断各位是否合法,不合法直接跳过,合法则输出。

如果total为0则输出NONE。

代码如下:

{
ID:asdcyt01
PROB:namenum
LANG:PASCAL
}
program namenum(input,output);
var
n,i,total:longint;
data:text;
ch:array[1..12]of integer;
str:string;
flag:boolean;
c:char;
begin
assign(input,'namenum.in');reset(input);
assign(output,'namenum.out');rewrite(output);
assign(data,'dict.txt');reset(data);
n:=0;
total:=0;
while not eoln do
begin
inc(n);
read(c);
ch
:=ord(c)-ord('0');
end;
while not eof(data) do
begin
readln(data,str);
if length(str)<>n then continue;
flag:=false;
for i:=1 to n do
case ch[i] of
2:if (str[i]<>'A')and(str[i]<>'B')and(str[i]<>'C')then begin flag:=true;break;end;
3:if (str[i]<>'D')and(str[i]<>'E')and(str[i]<>'F')then begin flag:=true;break;end;
4:if (str[i]<>'G')and(str[i]<>'H')and(str[i]<>'I')then begin flag:=true;break;end;
5:if (str[i]<>'J')and(str[i]<>'K')and(str[i]<>'L')then begin flag:=true;break;end;
6:if (str[i]<>'M')and(str[i]<>'N')and(str[i]<>'O')then begin flag:=true;break;end;
7:if (str[i]<>'P')and(str[i]<>'R')and(str[i]<>'S')then begin flag:=true;break;end;
8:if (str[i]<>'T')and(str[i]<>'U')and(str[i]<>'V')then begin flag:=true;break;end;
9:if (str[i]<>'W')and(str[i]<>'X')and(str[i]<>'Y')then begin flag:=true;break;end;
end;
if flag then continue;
writeln(str);
inc(total);
end;
if total=0 then writeln('NONE');
close(input);close(output);
end .
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: