会员
众包
新闻
博问
闪存
赞助商
HarmonyOS
Chat2DB
所有博客
当前博客
我的博客
我的园子
账号设置
会员中心
简洁模式
...
退出登录
注册
登录
SDJL的足迹
首页
博问
闪存
管理
USACO_1_2_Name That Number
/**/
/*
ID: sdjllyh1
PROG: namenum
LANG: JAVA
complete date: 2008/9/23
author: LiuYongHui From GuiZhou University Of China
more article: www.cnblogs.com/sdjls
*/
import
java.io.
*
;
import
java.util.
*
;
public
class
namenum
{
public
static
String sn
=
""
;
public
static
void
main(String[] args)
throws
IOException
{
init();
output();
System.exit(
0
);
}
private
static
void
init()
throws
IOException
{
BufferedReader f
=
new
BufferedReader(
new
FileReader(
"
namenum.in
"
));
StringTokenizer st
=
new
StringTokenizer(f.readLine());
sn
=
st.nextToken();
f.close();
}
private
static
void
output()
throws
IOException
{
PrintWriter out
=
new
PrintWriter(
new
BufferedWriter(
new
FileWriter(
"
namenum.out
"
)));
cow theCow
=
new
cow(sn);
ArrayList names
=
theCow.getNames();
if
(names.size()
==
0
)
{
out.println(
"
NONE
"
);
}
else
{
for
(
int
i
=
0
; i
<
names.size(); i
++
)
{
out.println(names.get(i));
}
}
out.close();
}
}
class
cow
{
String sn
=
""
;
ArrayList name
=
new
ArrayList();
public
cow(String sn)
throws
IOException
{
this
.sn
=
sn;
initNames();
}
public
ArrayList getNames()
{
return
this
.name;
}
private
void
initNames()
throws
IOException
{
BufferedReader f
=
new
BufferedReader(
new
FileReader(
"
dict.txt
"
));
for
(
int
i
=
0
; i
<
4167
; i
++
)
{
String word
=
f.readLine();
if
(wordToNum(word).equals(
this
.sn))
this
.name.add(word);
}
f.close();
}
private
String wordToNum(String word)
{
String num
=
""
;
for
(
int
i
=
0
; i
<
word.length(); i
++
)
num
+=
letterToNum(word.charAt(i));
return
num;
}
private
char
letterToNum(
char
letter)
{
char
num;
switch
(letter)
{
case
'
A
'
:
case
'
B
'
:
case
'
C
'
:
num
=
'
2
'
;
break
;
case
'
D
'
:
case
'
E
'
:
case
'
F
'
:
num
=
'
3
'
;
break
;
case
'
G
'
:
case
'
H
'
:
case
'
I
'
:
num
=
'
4
'
;
break
;
case
'
J
'
:
case
'
K
'
:
case
'
L
'
:
num
=
'
5
'
;
break
;
case
'
M
'
:
case
'
N
'
:
case
'
O
'
:
num
=
'
6
'
;
break
;
case
'
P
'
:
case
'
R
'
:
case
'
S
'
:
num
=
'
7
'
;
break
;
case
'
T
'
:
case
'
U
'
:
case
'
V
'
:
num
=
'
8
'
;
break
;
case
'
W
'
:
case
'
X
'
:
case
'
Y
'
:
num
=
'
9
'
;
break
;
default
:
num
=
'
0
'
;
break
;
}
return
num;
}
}
posted on
2008-09-23 20:40
刘永辉
阅读(
369
) 评论(
6
)
收藏
举报
刷新页面
返回顶部