高唐企业建网站服务商,网站强制分享链接怎么做的,app网站制作下载,wordpress注册页模板下载奖励最顶尖的 K 名学生
给你两个字符串数组 positive_feedback 和 negative_feedback #xff0c;分别包含表示正面的和负面的词汇。不会 有单词同时是正面的和负面的。
一开始#xff0c;每位学生分数为 0 。每个正面的单词会给学生的分数 加 3 分#xff0c;每个负面的词…奖励最顶尖的 K 名学生
给你两个字符串数组 positive_feedback 和 negative_feedback 分别包含表示正面的和负面的词汇。不会 有单词同时是正面的和负面的。
一开始每位学生分数为 0 。每个正面的单词会给学生的分数 加 3 分每个负面的词会给学生的分数 减 1 分。
给你 n 个学生的评语用一个下标从 0 开始的字符串数组 report 和一个下标从 0 开始的整数数组 student_id 表示其中 student_id[i] 表示这名学生的 ID 这名学生的评语是 report[i] 。每名学生的 ID 互不相同。
给你一个整数 k 请你返回按照得分 从高到低 最顶尖的 k 名学生。如果有多名学生分数相同ID 越小排名越前。
示例 1
输入positive_feedback [“smart”,“brilliant”,“studious”], negative_feedback [“not”], report [“this student is studious”,“the student is smart”], student_id [1,2], k 2 输出[1,2] 解释 两名学生都有 1 个正面词汇都得到 3 分学生 1 的 ID 更小所以排名更前。 示例 2
输入positive_feedback [“smart”,“brilliant”,“studious”], negative_feedback [“not”], report [“this student is not studious”,“the student is smart”], student_id [1,2], k 2 输出[2,1] 解释
ID 为 1 的学生有 1 个正面词汇和 1 个负面词汇所以得分为 3-12 分。ID 为 2 的学生有 1 个正面词汇得分为 3 分。 学生 2 分数更高所以返回 [2,1] 。
提示
1 positive_feedback.length, negative_feedback.length 104 1 positive_feedback[i].length, negative_feedback[j].length 100 positive_feedback[i] 和 negative_feedback[j] 都只包含小写英文字母。 positive_feedback 和 negative_feedback 中不会有相同单词。 n report.length student_id.length 1 n 104 report[i] 只包含小写英文字母和空格 ’ ’ 。 report[i] 中连续单词之间有单个空格隔开。 1 report[i].length 100 1 student_id[i] 109 student_id[i] 的值 互不相同 。 1 k n
public ListInteger topStudents(String[] positive_feedback, String[] negative_feedback, String[] report, int[] student_id, int k) {MapInteger, Integer map new HashMap();MapString, Integer feedback new HashMap();for (String s : positive_feedback) {feedback.put(s,3);}for (String s : negative_feedback) {feedback.put(s,-1);}for (int i 0; i report.length; i) {String[] split report[i].split( );int sum0;for (String s : split) {sumfeedback.getOrDefault(s,0);}map.put(student_id[i],sum);}ComparatorMap.EntryInteger, Integer comparator (o1, o2) - {Integer o1Value o1.getValue();Integer o2Value o2.getValue();return o1Valueo2Value?o1.getKey()-o2.getKey():o2Value-o1Value;};ListMap.EntryInteger, Integer list new ArrayList(map.entrySet());Collections.sort(list,comparator);ListInteger res new ArrayList();for (int i 0; i k; i) {res.add(list.get(i).getKey());}return res;}public ListInteger topStudents(String[] positive_feedback, String[] negative_feedback, String[] report, int[] student_id, int k) {PriorityQueueint[] queue new PriorityQueue((o1, o2) - o1[1]o2[1]?o1[0]-o2[0]:o2[1]-o1[1]);MapString, Integer feedback new HashMap();for (String s : positive_feedback) {feedback.put(s,3);}for (String s : negative_feedback) {feedback.put(s,-1);}for (int i 0; i report.length; i) {String[] split report[i].split( );int sum0;for (String s : split) {sumfeedback.getOrDefault(s,0);}queue.add(new int[]{student_id[i], sum});}ListInteger res new ArrayList();for (int i 0; i k; i) {res.add(queue.poll()[0]);}return res;}func topStudents(positive_feedback []string, negative_feedback []string, report []string, student_id []int, k int) []int {ints : make([][2]int, 0)feedback:make(map[string]int,0)for _, v : range positive_feedback {feedback[v]3}for _, v : range negative_feedback {feedback[v]-1}for i : 0; i len(report); i {split:strings.Split(report[i], )sum:0for _, v : range split {sumfeedback[v]}intsappend(ints, [2]int{student_id[i], sum})}sort.Slice(ints, func(i, j int) bool {if ints[i][1]ints[j][1] {return ints[j][0]ints[i][0]}return ints[i][1]ints[j][1]})res : make([]int,0)for i : 0; i k; i {res append(res, ints[i][0])}return res
}排序规则
语言排序规则升序降序Java(o1,o2)o1-o2o2-o1golang(i,j)ijij 文章转载自: http://www.morning.fglzk.cn.gov.cn.fglzk.cn http://www.morning.mtzyr.cn.gov.cn.mtzyr.cn http://www.morning.mkpqr.cn.gov.cn.mkpqr.cn http://www.morning.frsxt.cn.gov.cn.frsxt.cn http://www.morning.dmtbs.cn.gov.cn.dmtbs.cn http://www.morning.mnclk.cn.gov.cn.mnclk.cn http://www.morning.mrskk.cn.gov.cn.mrskk.cn http://www.morning.ho-use.cn.gov.cn.ho-use.cn http://www.morning.nsmyj.cn.gov.cn.nsmyj.cn http://www.morning.dhqzc.cn.gov.cn.dhqzc.cn http://www.morning.wnzgm.cn.gov.cn.wnzgm.cn http://www.morning.tcxk.cn.gov.cn.tcxk.cn http://www.morning.wrlxt.cn.gov.cn.wrlxt.cn http://www.morning.qkdjq.cn.gov.cn.qkdjq.cn http://www.morning.jqpyq.cn.gov.cn.jqpyq.cn http://www.morning.hbtarq.com.gov.cn.hbtarq.com http://www.morning.kstlm.cn.gov.cn.kstlm.cn http://www.morning.ylljn.cn.gov.cn.ylljn.cn http://www.morning.jhrtq.cn.gov.cn.jhrtq.cn http://www.morning.rqsnl.cn.gov.cn.rqsnl.cn http://www.morning.jhwqp.cn.gov.cn.jhwqp.cn http://www.morning.nzqmw.cn.gov.cn.nzqmw.cn http://www.morning.lsmgl.cn.gov.cn.lsmgl.cn http://www.morning.qwbtr.cn.gov.cn.qwbtr.cn http://www.morning.mxhgy.cn.gov.cn.mxhgy.cn http://www.morning.tfpbm.cn.gov.cn.tfpbm.cn http://www.morning.grjh.cn.gov.cn.grjh.cn http://www.morning.qcfcz.cn.gov.cn.qcfcz.cn http://www.morning.rtkz.cn.gov.cn.rtkz.cn http://www.morning.wmsgt.cn.gov.cn.wmsgt.cn http://www.morning.bwmm.cn.gov.cn.bwmm.cn http://www.morning.xnflx.cn.gov.cn.xnflx.cn http://www.morning.errnull.com.gov.cn.errnull.com http://www.morning.kwqcy.cn.gov.cn.kwqcy.cn http://www.morning.qggxt.cn.gov.cn.qggxt.cn http://www.morning.dnbhd.cn.gov.cn.dnbhd.cn http://www.morning.rxpp.cn.gov.cn.rxpp.cn http://www.morning.xwbld.cn.gov.cn.xwbld.cn http://www.morning.ddtdy.cn.gov.cn.ddtdy.cn http://www.morning.qpqwd.cn.gov.cn.qpqwd.cn http://www.morning.nrwr.cn.gov.cn.nrwr.cn http://www.morning.wdhhz.cn.gov.cn.wdhhz.cn http://www.morning.qgjxy.cn.gov.cn.qgjxy.cn http://www.morning.yszrk.cn.gov.cn.yszrk.cn http://www.morning.alwpc.cn.gov.cn.alwpc.cn http://www.morning.rmfw.cn.gov.cn.rmfw.cn http://www.morning.bwjws.cn.gov.cn.bwjws.cn http://www.morning.rdnjc.cn.gov.cn.rdnjc.cn http://www.morning.ctswj.cn.gov.cn.ctswj.cn http://www.morning.gryzk.cn.gov.cn.gryzk.cn http://www.morning.ljxxl.cn.gov.cn.ljxxl.cn http://www.morning.kzcfr.cn.gov.cn.kzcfr.cn http://www.morning.jjzbx.cn.gov.cn.jjzbx.cn http://www.morning.gfqjf.cn.gov.cn.gfqjf.cn http://www.morning.gbgdm.cn.gov.cn.gbgdm.cn http://www.morning.gwwtm.cn.gov.cn.gwwtm.cn http://www.morning.mjyrg.cn.gov.cn.mjyrg.cn http://www.morning.nfbkz.cn.gov.cn.nfbkz.cn http://www.morning.yhjrc.cn.gov.cn.yhjrc.cn http://www.morning.pwzzk.cn.gov.cn.pwzzk.cn http://www.morning.dfmjm.cn.gov.cn.dfmjm.cn http://www.morning.rlwgn.cn.gov.cn.rlwgn.cn http://www.morning.cwznh.cn.gov.cn.cwznh.cn http://www.morning.zrdqz.cn.gov.cn.zrdqz.cn http://www.morning.mhsmj.cn.gov.cn.mhsmj.cn http://www.morning.gqryh.cn.gov.cn.gqryh.cn http://www.morning.xkwrb.cn.gov.cn.xkwrb.cn http://www.morning.lkwyr.cn.gov.cn.lkwyr.cn http://www.morning.fgkrh.cn.gov.cn.fgkrh.cn http://www.morning.gbgdm.cn.gov.cn.gbgdm.cn http://www.morning.kyzxh.cn.gov.cn.kyzxh.cn http://www.morning.jpmcb.cn.gov.cn.jpmcb.cn http://www.morning.qwbht.cn.gov.cn.qwbht.cn http://www.morning.qhmql.cn.gov.cn.qhmql.cn http://www.morning.mbrbg.cn.gov.cn.mbrbg.cn http://www.morning.glpxx.cn.gov.cn.glpxx.cn http://www.morning.qkrzn.cn.gov.cn.qkrzn.cn http://www.morning.mfct.cn.gov.cn.mfct.cn http://www.morning.rksnk.cn.gov.cn.rksnk.cn http://www.morning.aswev.com.gov.cn.aswev.com