new group contact

2024-01-04 11:48
文章标签 new group contact

本文主要是介绍new group contact,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

之前的做法有bug

public class NewGroupContact {//http://www.fgdsb.com/2015/01/25/group-contacts/// http://www.1point3acres.com/bbs/thread-148422-1-1.html// http://www.1point3acres.com/bbs/forum.php?mod=viewthread&tid=192328&extra=page%3D1%26filter%3Dsortid%26sortid%3D311%26searchoption%255B3046%255D%255Bvalue%255D%3D2%26searchoption%255B3046%255D%255Btype%255D%3Dradio&page=1public static void main(String[] args) {HashMap<String/* string value */, Integer/* type */> st = new HashMap<>();HashMap<Integer/* type */, Set<String>/* type */> ts = new HashMap<>();// String[][] A = { { "John", "john@gmail.com", "john@fb.com" },// { "Dan", "dan@gmail.com", "+1234567" },// { "john123", "+5412312", "john123@skype.com" },// { "john1985", "+5412312", "john@fb.com" },// { "Dan12", "+1234567", "dan@fb.com" },// { "Shaohui", "+4125194763", "sguo@fb.com" }};String[][] A = { { "x", "y", "z" }, { "Shaohui" }, { "a", "b" }, { "k", "z" }, { "m", "a" },{ "Shaohui", "+4125194763", "sguo@fb.com", "x" } };int code = 0;for (int i = 0; i < A.length; i++) {int c = -1;Set<Integer/*type*/> groupings = new HashSet<Integer>();for (int j = 0; j < A[i].length; j++) {String s = A[i][j];if (st.containsKey(s)) {int value = st.get(s);groupings.add(value);c = Math.max(c, value);}}if (c == -1) {c = code++;} else {groupings.remove(c);Set<String> set = ts.get(c);for (Integer k : groupings) {if (ts.containsKey(k)) {Set<String> strs = ts.get(k);set.addAll(strs);ts.remove(k);}}}for (int j = 0; j < A[i].length; j++) {String s = A[i][j];st.put(s, c);if (ts.containsKey(c)) {ts.get(c).add(s);} else {ts.put(c, new HashSet<String>());ts.get(c).add(s);}}}for (Map.Entry<Integer, Set<String>> entry: ts.entrySet()) {System.out.print("group: " + entry.getKey() + " [");for (String str: entry.getValue()) {System.out.print(" "+str+" ");}System.out.println("]");}}
}


这篇关于new group contact的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/569237

相关文章

Python中__new__()方法适应及注意事项详解

《Python中__new__()方法适应及注意事项详解》:本文主要介绍Python中__new__()方法适应及注意事项的相关资料,new()方法是Python中的一个特殊构造方法,用于在创建对... 目录前言基本用法返回值单例模式自定义对象创建注意事项总结前言new() 方法在 python 中是一个

MySQL报错sql_mode=only_full_group_by的问题解决

《MySQL报错sql_mode=only_full_group_by的问题解决》本文主要介绍了MySQL报错sql_mode=only_full_group_by的问题解决,文中通过示例代码介绍的非... 目录报错信息DataGrip 报错还原Navicat 报错还原报错原因解决方案查看当前 sql mo

Golan中 new() 、 make() 和简短声明符的区别和使用

《Golan中new()、make()和简短声明符的区别和使用》Go语言中的new()、make()和简短声明符的区别和使用,new()用于分配内存并返回指针,make()用于初始化切片、映射... 详细介绍golang的new() 、 make() 和简短声明符的区别和使用。文章目录 `new()`

matlab读取NC文件(含group)

matlab读取NC文件(含group): NC文件数据结构: 代码: % 打开 NetCDF 文件filename = 'your_file.nc'; % 替换为你的文件名% 使用 netcdf.open 函数打开文件ncid = netcdf.open(filename, 'NC_NOWRITE');% 查看文件中的组% 假设我们想读取名为 "group1" 的组groupName

java线程深度解析(一)——java new 接口?匿名内部类给你答案

http://blog.csdn.net/daybreak1209/article/details/51305477 一、内部类 1、内部类初识 一般,一个类里主要包含类的方法和属性,但在Java中还提出在类中继续定义类(内部类)的概念。 内部类的定义:类的内部定义类 先来看一个实例 [html]  view plain copy pu

string字符会调用new分配堆内存吗

gcc的string默认大小是32个字节,字符串小于等于15直接保存在栈上,超过之后才会使用new分配。

AI辅助编程里的 Atom Group 的概念和使用

背景 在我们实际的开发当中,一个需求往往会涉及到多个文件修改,而需求也往往有相似性。 举个例子,我经常需要在 auto-coder中需要添加命令行参数,通常是这样的: /coding 添加一个新的命令行参数 --chat_model 默认值为空 实际上这个需求涉及到以下文件列表: /Users/allwefantasy/projects/auto-coder/src/autocoder/auto

List list = new ArrayList();和ArrayList list=new ArrayList();的区别?

List是一个接口,而ArrayList 是一个类。 ArrayList 继承并实现了List。 List list = new ArrayList();这句创建了一个ArrayList的对象后把上溯到了List。此时它是一个List对象了,有些ArrayList有但是List没有的属性和方法,它就不能再用了。而ArrayList list=new ArrayList();创建一对象则保留了A

group by 新体会

group by 分组语句中的 select 后面查询的东西,只能是 group by 中的字段或聚合函数,如果含有group by 中的没有的字段,sql 会报错。 表users   例子:  1.select count(1),sex from users group by sex; sql执行正确   2.select count(id),sex from users gr

vue原理分析(六)--研究new Vue()

今天我们来分析使用new Vue() 之前研究时,只是说是在创建一个实例。并没有深入进行研究 在vue的源码中找下Vue的构造函数 function Vue(options) {if (!(this instanceof Vue)) {warn$2('Vue is a constructor and should be called with the `new` keyword');}thi