一、GitHub仓库地址
https://github.com/viency-yy/131700146
二、PSP表格
PSP2.1 | Personal Software Process Stages | 预估耗时(分钟) | 实际耗时(分钟) |
---|---|---|---|
Planning | 计划 | 30 | 40 |
· Estimate | · 估计这个任务需要多少时间 | 840 | 800 |
Development | 开发 | 240 | 180 |
· Analysis | · 需求分析 (包括学习新技术) | 120 | 150 |
· Design Spec | · 生成设计文档 | 30 | 20 |
· Design Review | · 设计复审 | 20 | 15 |
· Coding Standard | · 代码规范 (为目前的开发制定合适的规范) | 20 | 25 |
· Design | · 具体设计 | 60 | 40 |
· Coding | · 具体编码 | 180 | 200 |
· Code Review | · 代码复审 | 30 | 30 |
· Test | · 测试(自我测试,修改代码,提交修改) | 20 | 30 |
· Reporting | · 报告 | 20 | 25 |
· Test Repor | · 测试报告 | 10 | 10 |
· Size Measurement | · 计算工作量 | 5 | 5 |
· Postmortem & Process Improvement Plan | · 事后总结, 并提出过程改进计划 | 60 | 40 |
合计 | 1685 | 1610 |
三、解题思路
刚拿到题目十分懵逼,完全不知道如何入手,前面几天一无所获。后来看到大佬说用json、正则表达式,就开始疯狂百度,大部分都是在CSDN博客和博客园中看大佬的解法,然后去理解他的,再去思考,以下流程图为大致思路。
method1:依次提取“省”、“市”、“区/县”、“街道/镇”,并将其从地址簿中切除
method2:依次提取“省”、“市”、“区/县”、“街道/镇”、“路”、“门牌号”,并将其从地址簿中切除
四、关键算法
1 public static void main(String[] args) throws IOException { 2 Main main=new Main(); 3 4 FileReader fileReader = new FileReader("E:\\test.txt"); 5 BufferedReader buf = new BufferedReader(fileReader); 6 String readLine = ""; 7 List<JSONObject> ads=new ArrayList<JSONObject>(); 8 while((readLine = buf.readLine()) != null){ 9 //System.out.println(readLine); 10 String flag=readLine.substring(0,1); 11 String address=readLine.substring(2); 12 13 if(flag.equals("1")) 14 { 15 JSONObject ad= main.method1(address); 16 ads.add(ad); 17 18 }else 19 { 20 JSONObject ad= main.method2(address); 21 ads.add(ad); 22 } 23 24 25 }
Pattern pattern = Pattern.compile("((13[0-9])|(14[5|7])|(15([0-3]|[5-9]))|(18[0,5-9]))\\d{8}"); // 创建匹配给定输入与此模式的匹配器。 Matcher matcher = pattern.matcher(str); //查找字符串中是否有符合的子字符串
JSONObject object = new JSONObject(); //获取姓名 int index = str.indexOf(‘,‘); String name = str.substring(0,index); object.put("姓名",name); //将姓名从地址簿中切除
[{"姓名":"李四","地址":["福建省","福州市","鼓楼区","鼓西街道","湖滨路","110号","湖滨大厦一层"],"手机":"13756899511"}, {"姓名":"张三","地址":["福建省","福州市","闽候县","上街镇","福州大学10#111"],"手机":"13599622362"}, {"姓名":"王五","地址":["福建省","福州市","鼓楼区","","五一北路","123号","福州鼓楼医院"],"手机":"18960221533"}, {"姓名":"小美","地址":["北京","北京市","东城区","","交道口东大街","1号","北京市东城区人民法院"],"手机":"15822153326"}, {"姓名":"小陈","地址":["广东省","东莞市","","凤岗镇","风平路13号"],"手机":"13965231525"}]
五、性能改进
用JProfiler生成一张性能分析图,但是第一次用,他的分析结果我也没看懂,也没时间了,就。。不知道如何改进了。我太菜了dbq
六、单元测试展示
七、异常处理说明
用正则表达式之后,就解决了
八、心路历程与收获
原文:https://www.cnblogs.com/zy159/p/11519856.html