模拟/usaco 1.2.3 Name That Number

题意

  给出一个数和每个数字可对应字母,求这个数可以对应的单词中哪些在字典里 字典给出

  输出单词 如果没有 输出NONE

分析

  因为每个数字可对应多个字母 我就把字典里所有单词都映射成数 再跟读进来的数进行比较...

Accepted Code

 1 {

 2 ID: jessiel2;

 3 PROG: namenum

 4 LANG: PASCAL

 5 }

 6 Program namenum;

 7 Const

 8   Infile = 'namenum.in';

 9   Outfile = 'namenum.out';

10   Dictionary = 'dict.txt';

11 Var

12   a,old:String;

13   f:Boolean;

14 Function check(s:String):String;

15 Var

16   i:Longint;

17   num:String;

18 Begin

19   num:='';

20   For i:=1 To length(s) Do Begin

21       Case s[i] Of

22         'A','B','C':

23             num:=num+'2';

24         'D','E','F':

25             num:=num+'3';

26         'G','H','I':

27             num:=num+'4';

28         'J','K','L':

29             num:=num+'5';

30         'M','N','O':

31             num:=num+'6';

32         'P','R','S':

33             num:=num+'7';

34         'T','U','V':

35             num:=num+'8';

36         'W','X','Y':

37             num:=num+'9';

38       End;

39   End;

40   Exit(num);

41 End;

42 

43 Begin

44   Assign(input,infile);Reset(input);

45   ReadLn(old);

46   Close(input);

47   Assign(input,dictionary);Reset(input);

48   Assign(output,outfile);Rewrite(output);

49   f:=false;

50   While not eof Do Begin

51     ReadLn(a);

52     If check(a)=old Then Begin

53       WriteLn(a);

54       f:=true;

55     End;

56   End;

57   If not f Then WriteLn('NONE');

58   Close(input);Close(output);

59 End.

 

你可能感兴趣的:(number)