-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1035.cpp
More file actions
48 lines (44 loc) · 712 Bytes
/
1035.cpp
File metadata and controls
48 lines (44 loc) · 712 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
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
int n;
cin >>n;
int *a=new int[n];
int *b=new int[n];
for(int i=0;i<n;i++){
cin>>a[i];
}
for(int i=0;i<n;i++){
cin>>b[i];
}
int i,j;
for(i=0;b[i]<=b[i+1]&&i<n;i++);
for(j=i+1;a[j]==b[j]&&j<n;j++);
if(j==n){
cout<<"Insertion Sort"<<endl;
sort(a,a+i+2);
}else{
cout<<"Merge Sort"<<endl;
int k=1;
bool flag = true;
while(flag){
flag=false;
k=k*2;
for(int l=0;l<n;l++){
if(a[l]!=b[l])
flag = true;
}
for(int l=0;l<n/k;l++){
sort(a+l*k,a+(l+1)*k);
}
sort(a+(n/k*k),a+n);
}
}
for(int i=0;i<n-1;i++){
cout<<a[i]<<" ";
}
cout<<a[n-1]<<endl;
system("pause");
return 0;
}