contact
来源:互联网 发布:linux scp 文件夹 编辑:程序博客网 时间:2024/05/16 08:53
/*ID: daniel.20LANG: JAVATASK: contact */import java.io.*;import java.util.*;class myComparator implements Comparator<String> {public int compare(String o1, String o2) {if (o1.length() == o2.length()) {return o1.compareTo(o2);} else {return o1.length() - o2.length();}}}public class contact {static int a, b, n;static char[] source;static int len;public static void initial() throws Exception {BufferedReader reader = new BufferedReader(new FileReader("contact.in"));StringTokenizer st = new StringTokenizer(reader.readLine());a = Integer.parseInt(st.nextToken());b = Integer.parseInt(st.nextToken());n = Integer.parseInt(st.nextToken());source = new char[200002];String tmp = "";int start = 0;while ((tmp = reader.readLine()) != null) {for (int i = 0; i < tmp.length(); ++i) {source[start + i] = tmp.charAt(i);}start += tmp.length();}len = start;}public static void work() throws Exception {HashMap<String, Integer> hm = new HashMap<String, Integer>();int max = 0;PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter("contact.out")));for (int i = 0; i < len; ++i) {for (int j = a; j <= b; ++j) {if (i - j + 1 < 0)break;String tmp = "";for (int k = i - j + 1; k < i + 1; ++k) {tmp += source[k];}if (hm.containsKey(tmp)) {int time = hm.get(tmp);hm.put(tmp, time + 1);max = time + 1 > max ? time + 1 : max;} else {hm.put(tmp, 1);}}}HashMap<Integer, ArrayList<String>> hm1 = new HashMap<Integer, ArrayList<String>>();Set<String> keys = hm.keySet();Iterator<String> it = keys.iterator();while (it.hasNext()) {String key = it.next();int value = hm.get(key);if (hm1.containsKey(value)) {hm1.get(value).add(key);} else {hm1.put(value, new ArrayList<String>());hm1.get(value).add(key);}}Set<Integer> k = hm1.keySet();ArrayList<Integer> al = new ArrayList<Integer>(k);Collections.sort(al, Collections.reverseOrder());int upper = n>al.size()?al.size():n;for (int i = 0; i < upper; ++i) {ArrayList<String> att = hm1.get(al.get(i));out.println(al.get(i));Collections.sort(att,new myComparator());for (int j = 0; j < att.size(); ++j) {if (j != att.size() - 1&&(j+1)%6!=0) {out.print(att.get(j) + " ");} else {out.println(att.get(j));}}}out.close();}public static void main(String[] args) throws Exception {initial();work();}}
This is not an elegant code. Furture study will be done.
I'll upload another version soon, a bit opertation version, possibly.
- contact
- Contact
- Contact
- contact
- Contact
- Contact
- contact
- USACO 3.1 Contact (contact)
- USACO3.1.4 Contact (contact)
- USACO3.1.4 Contact (contact)
- Contact me
- Contact Us
- usaco contact
- Contact类
- Contact Me
- usaco Contact
- USACO-Contact
- Contact 笔记
- JS常用操作
- 将Sqlserver表数据导出成insert into语句 .
- 经典回顾:2005年乔布斯在斯坦福大学毕业典礼上的演讲
- windows程序調試.pdf
- Java实现穷举密码登录FTP服务器
- contact
- 基于ARM-LINUX的温度传感器驱动(一)
- 从 VC7 的 CHtmlView 不能正常退出谈 CComPtr 使用中的一个误区
- 常用地址连接
- 根据HEX颜色创建UIColor和获取UIColor颜色分量
- 信息学子另眼看乔布斯— 谈程序员的未来
- 你确定你了解widows文件夹的含义吗?——亲爱的内存溢出
- IT人员从业方向
- SQL查询前10条记录(SqlServer/mysql/oracle/sybase)[语法分析]