-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathQuestionsAnswers.kt
50 lines (36 loc) · 930 Bytes
/
QuestionsAnswers.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
fun main(args: Array<String>) {
var cnt = readLine()!!.toInt();
val dict = mutableListOf<Int>();
for (i in 1..cnt) {
dict.add( readLine()!!.toInt() );
}
radixSort(dict);
readLine();
val reqs = readLine()!!.toInt();
for (i in 1..reqs) {
println(dict[readLine()!!.toInt()-1] );
}
}
fun radixSort(list:MutableList<Int>) {
val tmp = IntArray(list.size,{0});
for (i in 0..13) {
var lCnt = 0;
var rCnt = tmp.size-1;
val mask = 1 shl i;
for (j in list) {
if (j and mask == 0) {
tmp[lCnt++]=j;
}
else {
tmp[rCnt--]=j;
}
}
for (k in 0..lCnt-1) {
list[k]=tmp[k];
}
var p = lCnt;
for (k in tmp.size-1 downTo lCnt) {
list[p++]=tmp[k];
}
}
}