第二题思路,求问这个思路哪里的问题? public int exams(int e, int em, int m, int mh, int h) { int count = 0; while (em >= 0 && mh >= 0) { int min = Math.min(e, Math.min(m, h)); count += min; e -= min; m -= min; h -= min; if (e == 0) { e++; em--; } if (m == 0 ){ m++; if (em >= mh) em--; else mh--; } if (h ==0 ){ h++; mh--; } } return count; }
万万没想到第一题跪了,始终30%,大佬可以帮忙找找原因吗? import java.util.HashMap; import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); //输入单词总数 int n = in.nextInt(); //单词数组 String[] s = new String[n]; HashMap<String, Integer> map = new HashMap<>(); //统计单词数量 for (int i = 0; i < n; i++) { s[i] = in.next(); if (map.containsKey(s[i])) { map.put(s[i], map.get(s[i]) + 1); } else { map.put(s[i], 1); } } //统计满足条件单词数量 int count = 0; for (Integer ss : map.values()) { double p = (ss / n) * 100; if (p >= 1) { count++; } } System.out.println(count); } }