ITeye博客

该记住的人

oyprunner · 2010-01-12 20:18 · 编程语言 · Markdown

转眼见,忘记了好多人.... 写个程序记录用

import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Collections;

public class Test{	
	public static void main(String[] args) {
		try {
			HashMap<String,List<String>> hashMap = new HashMap<String,List<String>>();
			BufferedReader br = new BufferedReader(new FileReader(new File("c:\\md.txt")));
			String readLine = br.readLine();
			String[] str;
			while (!"end".equals(readLine)) {
				str = readLine.split(" ");
				if (str.length >= 2) {
					List<String> list = new ArrayList<String>(); 
					String key = str[0];
					if (!hashMap.containsKey(key)) {
						for(int i = 1 ; i < str.length ; i ++) {
							if(!"".equals(str[i]))
							   list.add(str[i]);
						}
						hashMap.put(key, list);
					} else {
						for(int i = 1 ; i < str.length ; i ++) {
						   if(!"".equals(str[i]))
							 hashMap.get(key).add(str[i]);
						} 
					}
				}
				readLine = br.readLine();
			}
			showName("北京",hashMap);
			showName("广州保险二期",hashMap);
			showName("广州华智",hashMap);
			showName("大学",hashMap);
			showName("高中",hashMap);
			showName("初中",hashMap);
			showName("小学",hashMap);
			System.out.println("\t总共"+sum+"人");
			
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	public static int sum;
	public static void showName(String key ,HashMap<String,List<String>> hashMap) {
		System.out.println("\t--> "+key);
		List  list= hashMap.get(key);
		int total = 0;
		for (int i = 0 ; i < list.size(); i++) {
			System.out.print("\t"+list.get(i)+" ");
			total++;
			if ((i+1)%8 == 0){
				System.out.println();
			}
		}
		System.out.println("\t"+total+"人\n");
		sum += total;
	}
}

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。