java两个数组[5,5]跟[4,4,2]比较生成[4,1,3,2]新数组。
含义是1,2,3,4,5,6,7,8,9,0分别分为两组,
第一组:5个5个一组{[12345],[67890]}
第二组:4个4个2个一组{[1234],[5678],[90]}
相互比较得出匹配数量
a1b1=4
a1b2=1
a2b2=3
a2b3=2
java两个数组[5,5]跟[4,4,2]比较生成[4,1,3,2]新数组
- 写回答
- 好问题 0 提建议
- 追加酬金
- 关注问题
- 邀请回答
-
2条回答 默认 最新
- threenewbee 2020-05-27 00:18关注
不明白为什么只比较a1b1 a1b2 a2b2 a2b3,而没有a1b3 a2b1
不过按照你的意思直接比较就可以了
以下代码手写的,只是思路public static int cnt(arraylist<Integer> a, arraylist<Integer> b) { int n = 0; arraylist<Integer> c = a.clone(); c.removeAll(b); return a.length() -c.length(); } public static void main(String args[]) { int[] an = new int[] {5,5}; int[] bn = new int[] {4,4,2}; arraylist<arraylist<Integer>> a = new arraylist<arraylist<Integer>>(); arraylist<arraylist<Integer>> b = new arraylist<arraylist<Integer>>(); int acc = 1; for (int i = 0; i < an.length(); i++) { a.add(new arraylist<Integer>()); for (int j = 0; j < an[i]; j++) a.get(i).add(new integer(acc)); acc++; } acc = 1; for (int i = 0; i < bn.length(); i++) { b.add(new arraylist<Integer>()); for (int j = 0; j < bn[i]; j++) b.get(i).add(new integer(acc)); acc++; } System.out.println(cnt(a.get(0), b.get(0))); System.out.println(cnt(a.get(0), b.get(1))); System.out.println(cnt(a.get(1), b.get(1))); System.out.println(cnt(a.get(1), b.get(2))); }
解决 无用评论 打赏 举报
悬赏问题
- ¥100 关于使用MATLAB中copularnd函数的问题
- ¥20 在虚拟机的pycharm上
- ¥15 jupyterthemes 设置完毕后没有效果
- ¥15 matlab图像高斯低通滤波
- ¥15 针对曲面部件的制孔路径规划,大家有什么思路吗
- ¥15 钢筋实图交点识别,机器视觉代码
- ¥15 如何在Linux系统中,但是在window系统上idea里面可以正常运行?(相关搜索:jar包)
- ¥50 400g qsfp 光模块iphy方案
- ¥15 两块ADC0804用proteus仿真时,出现异常
- ¥15 关于风控系统,如何去选择