- 5
- 0
- 约9.48千字
- 约 9页
- 2016-12-22 发布于湖南
- 举报
更多面试题,
百度面试笔试题 解答答案专家回答:第一题?? 简评?? 百度的主要业务是搜索,搜索的基本原理如下 1.编写爬虫程序到互联网上抓取网页海量的网页。 2.将抓取来的网页通过抽取,以一定的格式保存在能快速检索的文件系统中。 3.把用户输入的字符串进行拆分成关键字去文件系统中查询并返回结果。 由以上3点可见,字符串的分析,抽取在搜索引擎中的地位是何等重要。 因此,百度的笔试面试题中,出现这样的题就变得理所当然了。 以下是该题的java实现,代码如下:程序代码 程序代码import .*;import java.io.*;import java.util.*;/** * @author tzy * 在j2sdk1.4.2下测试通过 */public class FileNameStat{??? private String srcPath;//要统计的文件路径??? private Map statMap;//用于统计的map??? ??? public FileNameStat(String srcPath)??? {?????? this.srcPath=srcPath; 软件开发网 ?????? statMap=new TreeMap();??? }??? ??? /*获得要统计的URL的文件名*/??? public String getFileName(String urlString)??? {?????? URL url=null;?????? String filePath=null;?????? String fileName=null;?????? try?????? {?????????? url=new URL(urlString);?????????? filePath=url.getPath();?????????? int index=0;?????????? if ((index=filePath.lastIndexOf(/))!=-1)?????????? {?????????? fileName=filePath.substring(index+1); ?????????? }?????????? else?????????? {?????????????? fileName=;?????????? }?????? }?????? catch(MalformedURLException e)?????? {?????? }?????? return fileName;??? }??? ??? /*统计指定文件名的个数*/??? public void stat(String filename)??? {?????? Integer count=null;?????? if(statMap.get(filename)!=null)?????? {?????????? count=(Integer)statMap.get(filename); ?????????? count=new Integer(Value()+1);?????? }?????? else?????? {?????????? count=new Integer(1);?????? }?????? statMap.put(filename,count);??? }??? ??? /*统计的主方法*/??? public void start() throws FileNotFoundException,IOException??? {?????? BufferedReader bfin=new BufferedReader(new FileReader(this.srcPath));?????? String temp=null;?????? while((temp=bfin.readLine())!=null)?????? {?????????? stat(getFileName(temp));
?????? }??? }??? ??? /*输出统计结果*/??? public void result()??? {?????? Iterator it=statMap.entrySet().iterator();?????? while(it.hasNext())?????? {?????????? Map.Entry entry=(Map.Entry)(it.next());?????????? System.out.
您可能关注的文档
- 白酒市个场分析报告.doc
- 白酒市场w运作.doc
- 白酒市场操作据方案.doc
- 白酒市场策划方实案.doc
- 白酒市场销函售方案.doc
- 白酒有害成分个介绍.doc
- 白酒推广策个略.doc
- 白酒营销l之餐饮营销策略.doc
- 白酒铺q货知识文档.doc
- 白酒酿酒师国函家职业技能 培训与鉴定.doc
- 2025-2026学年天津市和平区高三(上)期末数学试卷(含解析).pdf
- 2025-2026学年云南省楚雄州高三(上)期末数学试卷(含答案).pdf
- 2025-2026学年甘肃省天水市张家川实验中学高三(上)期末数学试卷(含答案).docx
- 2025-2026学年福建省厦门市松柏中学高二(上)期末数学试卷(含答案).docx
- 2025-2026学年广西钦州市高一(上)期末物理试卷(含答案).docx
- 2025-2026学年河北省邯郸市临漳县九年级(上)期末化学试卷(含答案).docx
- 2025-2026学年河北省石家庄二十三中七年级(上)期末历史试卷(含答案).docx
- 2025-2026学年海南省五指山市九年级(上)期末化学试卷(含答案).docx
- 2025-2026学年河北省唐山市玉田县九年级(上)期末化学试卷(含答案).docx
- 2025-2026学年河北省邢台市市区九年级(上)期末化学试卷(含答案).docx
原创力文档

文档评论(0)