forked from amankayat/HackerRank-Solution-Algorithm-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcopy_jim_order.cpp
More file actions
58 lines (48 loc) · 956 Bytes
/
copy_jim_order.cpp
File metadata and controls
58 lines (48 loc) · 956 Bytes
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
53
54
55
56
57
58
#include<iostream>
using namespace std;
int main(){
int n;
cin>>n;
int a[n][2];
for(int i=0;i<n;i++){
for(int j=0;j<2;j++){
cin>>a[i][j];
}
}
int sum=0;
int temp[n];
for(int i=0;i<n;i++){
for(int j=0;j<2;j++){
sum+=a[i][j];
}
temp[i] = sum;
sum=0;
}
int copy_temp[n];
for(int i=0;i<n;i++)
copy_temp[i] = temp[i];
for(int i=1;i<n;i++){
for(int j=i;j>0;j--){
if(temp[j] < temp[j-1]){
int var = temp[j];
temp[j] = temp[j-1];
temp[j-1] = var;
}
}
}
int index[n];
int l=0;
for(int i=0;i<n;i++)
{ for(int j=0;j<n;j++){
if(temp[i]==copy_temp[j]){
index[l] = j+1;
l++;
copy_temp[j] = -1;
break;
}
}
}
//display
for(int i=0;i<l;i++)
cout<<index[i]<<" ";
}