第二道,始终不知道哪出了问题,28.7%,坐着怀疑人生 import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map.Entry; import java.util.Scanner; import java.util.Set; public class Main2 { public static void main(String[] args) { Scanner in = new Scanner(System.in); char[] output = new char[100]; int m = in.nextInt(); NumberOffGame(m, output); in.close(); } static void NumberOffGame(int m, char[] output) { if(m<=1 || m>=100) { System.out.println("ERROR!"); } else { HashMap<Integer, Integer> fc = new HashMap<Integer, Integer>(); for(int i=1; i<=100; i++) { fc.put(i, i); } int count=1; List<Integer> flag = new ArrayList<Integer>(); while(fc.keySet().size() >= m) { Set<Integer> key = fc.keySet(); for(Integer k : key) { if(count == m) { flag.add(k); count = 1; } else { count++; } } for(int i=0; i<flag.size(); i++) { fc.remove(flag.get(i)); } flag.clear(); } count = 0;  for(Entry<Integer, Integer> entry : fc.entrySet()) { System.out.printf("%d",entry.getKey()); if(count!=fc.size()-1) { System.out.printf(","); } count++; } } } }
点赞 1

相关推荐

勉勉强强过了两题,没发挥好
投递字节跳动等公司10个岗位
点赞 评论 收藏
分享
09-15 18:37
已编辑
门头沟学院 后端工程师
让校招回归公平好吗。各大公司学习一下
秋招路在何方:互娱和雷火的笔试是确实是我见过最严格的,支持
点赞 评论 收藏
分享
牛客网
牛客网在线编程
牛客网题解
牛客企业服务