3条回答 默认 最新
- 小带鱼 2019-01-19 19:50关注
你的意思我看懂了,但是你举的例子最后一行数字按照你的规律说,答案是错的。(六个对号四个错号),按照你的规律来说,应该是两个错,八个对。
3:234789 交集 null = null 叉
9:15610 交集 3 = null 叉
5:234789 交集 39 = 39 勾
2:234789 交集 395 = 39 勾
4:234789 交集 3952 = 239 勾
8:234789 交集 39524 = 2349 勾
1:15610 交集 395248 = 5 勾
7:15610 交集 3952481 = 15 勾
10:234789 交集 39524817 = 234789 勾
6:15610 交集 3952481710 = 1510 勾
你先确定一下这个规律是不是对的,如果确定了规律,出JAVA的算法很容易import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Scanner; public class Myclass01 { private HashMap<Integer,List<Integer>> map = new HashMap<Integer, List<Integer>>(); public static void main(String[] args) { new Myclass01(); } public Myclass01() { System.out.print("请自行输入一串数字(0代表10):"); Scanner scan = new Scanner(System.in); String read = scan.nextLine(); if(!read.matches("\\d+")){ System.out.println("输入的必须都是数字!"); return; } char[] ch = read.toCharArray(); int [] nums_input = new int[ch.length]; for (int i = 0; i < ch.length; i++) { nums_input[i] = Integer.parseInt(String.valueOf(ch[i])); } initialization(); List<Integer> nums_input_list = new ArrayList<Integer>(); for (int i = 0; i < nums_input.length; i++) { int num = nums_input[i]; nums_input_list.add(num); } for (int i = 0; i < nums_input_list.size(); i++) { int num = nums_input_list.get(i); if(num==0){ num = 10; } List<Integer> nums_list = map.get(num); if(i==0){ System.out.println(num+":×"); }else{ int before = nums_input_list.get(i-1); if(nums_list.contains(before)){ System.out.println(num+":√"); }else{ System.out.println(num+":×"); } } } } private int[] getRandomNum(int count) { // TODO 自动生成的方法存根 int[] nums = new int[count]; for (int i = 0; i < count; i++) { nums[i] = (int)(1+Math.random()*(10-1+1)); } return nums; } private void initialization() { List<Integer> nums_1 = new ArrayList<Integer>(); nums_1.add(1); nums_1.add(5); nums_1.add(6); nums_1.add(10); List<Integer> nums_2 = new ArrayList<Integer>(); nums_2.add(2); nums_2.add(3); nums_2.add(4); nums_2.add(7); nums_2.add(8); nums_2.add(9); map.put(1,nums_1); map.put(2, nums_2); map.put(3, nums_2); map.put(4, nums_2); map.put(5, nums_2); map.put(6, nums_1); map.put(7, nums_1); map.put(8, nums_2); map.put(9, nums_1); map.put(10, nums_2); } }
运行结果是:
3:×
9:×
5:√
2:×
4:√
8:√
1:×
7:√
10:√
6:√本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报
悬赏问题
- ¥50 power BI 从Mysql服务器导入数据,但连接进去后显示表无数据
- ¥15 (关键词-阻抗匹配,HFSS,RFID标签)
- ¥50 sft下载大文阻塞卡死
- ¥15 机器人轨迹规划相关问题
- ¥15 word样式右侧翻页键消失
- ¥15 springboot+vue 集成keycloak sso到阿里云
- ¥15 win7系统进入桌面过一秒后突然黑屏
- ¥30 backtrader对于期货交易的现金和资产计算的问题
- ¥15 求C# .net4.8小报表工具
- ¥15 安装虚拟机时出现问题