USACO_1_2_Name That Number

 

ExpandedBlockStart.gif ContractedBlock.gif /**/ /*
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
ExpandedBlockStart.gifContractedBlock.gif
{

    
public static String sn = "";

    
public static void main(String[] args) throws IOException
ExpandedSubBlockStart.gifContractedSubBlock.gif    
{
        init();
        output();
        System.exit(
0);
    }


    
private static void init() throws IOException
ExpandedSubBlockStart.gifContractedSubBlock.gif    
{
        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
ExpandedSubBlockStart.gifContractedSubBlock.gif    
{
        PrintWriter out 
= new PrintWriter(new BufferedWriter(new FileWriter("namenum.out")));

        cow theCow 
= new cow(sn);
        ArrayList names 
= theCow.getNames();
        
if (names.size() == 0)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
{
            out.println(
"NONE");
        }

        
else
ExpandedSubBlockStart.gifContractedSubBlock.gif        
{
            
for (int i = 0; i < names.size(); i++)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
{
                out.println(names.get(i));
            }
    
        }
        
        out.close();
    }

}


class  cow
ExpandedBlockStart.gifContractedBlock.gif
{
    String sn 
= "";
    ArrayList name 
= new ArrayList();

    
public cow(String sn) throws IOException
ExpandedSubBlockStart.gifContractedSubBlock.gif    
{
        
this.sn = sn;
        initNames();
    }


    
public ArrayList getNames()
ExpandedSubBlockStart.gifContractedSubBlock.gif    
{
        
return this.name;
    }


    
private void initNames() throws IOException
ExpandedSubBlockStart.gifContractedSubBlock.gif    
{
        BufferedReader f 
= new BufferedReader(new FileReader("dict.txt"));
        
        
for (int i = 0; i < 4167; i++)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
{
            String word 
= f.readLine();

            
if (wordToNum(word).equals(this.sn))
                
this.name.add(word);
        }

        f.close();
    }


    
private String wordToNum(String word)
ExpandedSubBlockStart.gifContractedSubBlock.gif    
{
        String num 
= "";
        
for (int i = 0; i < word.length(); i++)
            num 
+= letterToNum(word.charAt(i));
        
return num;
    }


    
private char letterToNum(char letter)
ExpandedSubBlockStart.gifContractedSubBlock.gif    
{
        
char num;
        
switch (letter)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
{
            
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;
    }


}

转载于:https://www.cnblogs.com/SDJL/archive/2008/09/23/1297413.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值