凑巧,就用了个HashMap最后遍历hashmap一趟,大于则++。 import java.util.HashMap; import java.util.Map; import java.util.Scanner; public class Mainh { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); while (scanner.hasNext()) { String[] line1 = scanner.nextLine().split(" "); int target = Integer.valueOf(line1[2]); String[] remain = scanner.nextLine().split(" "); HashMap<Integer, Integer> hashMap = new HashMap<>(); for (int i = 0; i < remain.length; i++) { hashMap.put(i+1,Integer.valueOf(remain[i])); } int nextLines = Integer.valueOf(line1[1]); String tmp; int key; while (nextLines > 0){ tmp = scanner.nextLine(); key = Integer.valueOf(tmp.split(" ")[1]); if (tmp.contains("A")){ hashMap.put(key, hashMap.get(key) + 1); }else hashMap.put(key, hashMap.get(key) - 1); nextLines--; } int topK = 1; int targetValue = hashMap.get(target); for (Map.Entry<Integer, Integer> entry : hashMap.entrySet()) { if (Integer.valueOf(entry.getValue()) > targetValue){ topK += 1; } } System.out.println(topK); } } } /* 3 4 2 5 3 1 B 1 A 2 A 2 A 3 */
点赞 2

相关推荐

烤点老白薯:他第二句话的潜台词是想让你帮他点个瑞幸或者喜茶啥的
mt对你说过最有启发的一...
点赞 评论 收藏
分享
牛客网
牛客网在线编程
牛客网题解
牛客企业服务