-
Notifications
You must be signed in to change notification settings - Fork 13
/
DsaQuestion
52 lines (52 loc) · 1.24 KB
/
DsaQuestion
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
50
51
52
//Enter code here
function runProgram(input) {
input=input.trim().split("\n")
let n=+input[0];
let arr=input[1].trim().split(" ").map(Number)
Sortout(n,arr)
}
function Sortout(n,arr){
var arr2=[];
for(var i=0; i<n; i++)
{
arr2.push(i)
}
for(var i=0; i<n; i++)
{
for(var j=0; j<n; j++)
{
if(arr[j]>arr[j+1])
{
var temp;
var temp2;
temp=arr[j]
arr[j]=arr[j+1];
arr[j+1]=temp;
temp2=arr2[j]
arr2[j]=arr2[j+1]
arr2[j+1]=temp2
}
}
}
console.log(arr2.join(" "))
}
if (process.env.USERNAME === "") {
runProgram(``);
} else {
process.stdin.resume();
process.stdin.setEncoding("ascii");
let read = "";
process.stdin.on("data", function (input) {
read += input;
});
process.stdin.on("end", function () {
read = read.replace(/\n$/, "");
read = read.replace(/\n$/, "");
runProgram(read);
});
process.on("SIGINT", function () {
read = read.replace(/\n$/, "");
runProgram(read);
process.exit(0);
});
}