搜狐这1个半小时的笔试 35分完成,好简单,附题解
这个编程题测试点有点水啊
import java.util.*;
public class Main{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
if(n == 0){
System.out.println(0);
return;
}
HashMap<Integer, Integer> day = new HashMap<>();
HashMap<Integer, Integer> task = new HashMap<>();
int res = 0;
int maxday = -1;
for(int i = 0 ; i < n ; i++){
int type = sc.nextInt();
if(type == 1){
int start = sc.nextInt();
int end = sc.nextInt();
maxday = Math.max(maxday, end);
int up = sc.nextInt();
for(int j = start ;j <= end; j++){
if(!day.containsKey(j)){
day.put(j, up);
}else{
int temp = Math.max(day.get(j), up);
day.put(j, temp);
}
}
}else if(type == 2){
int taskday = sc.nextInt();
int taskup = sc.nextInt();
maxday = Math.max(maxday, taskday);
if(task.containsKey(taskday)){
int now = task.get(taskday);
task.put(taskday, taskup + now);
}else{
task.put(taskday, taskup);
}
}
}
for(int i = 1; i <= maxday ; i++){
if(day.containsKey(i)){
res += day.get(i);
}
if(task.containsKey(i)){
res += task.get(i);
}
}
System.out.print(res);
}
}
import java.util.*;
public class Main{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int k = sc.nextInt();
Queue<Integer> q = new PriorityQueue<Integer>();
//ArrayList<Integer> list = new ArrayList<Integer>();
for(int i =0 ; i < n ; i++){
q.add(sc.nextInt());
}
for(int i = 0 ; i < k - 1; i++){
System.out.print(q.poll() + ",");
}
System.out.print(q.poll());
}
}
