主题:初中生求助
sablelr
[专家分:0] 发布于 2006-08-22 11:31:00
usaco1.2 Name That Number
那题,有2个问题捆饶:
1.字典文件的使用。
2.如何生成可能的情况。
谢谢各位大虾相助..
回复列表 (共3个回复)
沙发
sablelr [专家分:0] 发布于 2006-08-22 15:51:00
program namenum(input,output);
var
i,j,x,s,n,c,d:longint;
num:int64;
str:string;
h:boolean;
ch:array[1..5000]of char;
b,a:array[1..5000]of longint;
begin
assign(input,'namenum.in');
reset(input);
readln(num);
close(input);
assign(output,'namenum.out');
rewrite(output);
assign(input,'dict.txt');
reset(input);
n:=trunc(ln(num)/ln(10))+1;
for j:= n downto 1 do
begin
a[j]:=num mod 10;
num:=num div 10;
if (a[j]=1) or (a[j]=0) then
begin
writeln(output,'NONE');
end;
end;
for i:= 1 to 5000 do
begin
read(str);s:=length(str);
for x:= 1 to s do
begin
ch[x]:=str[x];
end;
if n=s then
begin
for j:=1 to s do
begin
if (ch[j]='Q') or (ch[j]='Z') then break;
if (ch[j] in ['A','B','C']) then b[j]:=2;
if (ch[j] in ['D','E','F']) then b[j]:=3;
if (ch[j] in ['G','H','I']) then b[j]:=4;
if (ch[j] in ['J','K','L']) then b[j]:=5;
if (ch[j] in ['M','N','O']) then b[j]:=6;
if (ch[j] in ['P','R','S']) then b[j]:=7;
if (ch[j] in ['T','U','V']) then b[j]:=8;
if (ch[j] in ['W','X','Y']) then b[j]:=9;
end;
d:=1;
while d<>n do
begin
if b[d]=a[d] then inc(d)
else break;
end;
if d=n then
begin
writeln(output,str);inc(c);
end;
end;
readln;
end;
if c=0 then writeln(output,'NONE');
close(input);
close(output);
end.
------------------------------------------------
程序写出来了,请大虾们帮我看看有没有什么问题。。
板凳
贺天行宝 [专家分:2300] 发布于 2006-08-22 20:20:00
{
ID:htx_2001
PROB:namenum
LANG:PASCAL
}
var
a,b:string;
i,j,k,l:longint;
c:char;
flag:boolean;
begin
assign(input,'namenum.in');reset(input);
readln(a);
close(input);
assign(input,'dict.txt');reset(input);
assign(output,'namenum.out');rewrite(output);
flag:=false;
while not eof do
begin
readln(b);
if length(b)=length(a) then begin
k:=0;
for i:=1 to length(b) do
begin
case b[i] of
'A'..'C':c:='2';
'D'..'F':c:='3';
'G'..'I':c:='4';
'J'..'L':C:='5';
'M'..'O':C:='6';
'P','R','S':C:='7';
'T'..'V':C:='8';
'W'..'Y':C:='9';
end;
if c<>a[i] then begin k:=1; end;
end;
if k=0 then begin writeln(b);flag:=true; end;
end;
end;
if not flag then writeln('NONE');
close(input);close(output);
end.
3 楼
贺天行宝 [专家分:2300] 发布于 2006-08-22 20:21:00
这是我写的,你跟踪你自己试试?
我来回复