-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path27.c
78 lines (74 loc) · 1.12 KB
/
27.c
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#include<stdio.h>
#include<stdlib.h>
void input(int **p1,int *n1);
int cmp(int a,int b);
int main()
{
int *p1,*p2,*p3,n1,n2;
int i,j,r;
input(&p1,&n1);
input(&p2,&n2);
p3=(int*)calloc(n1+n2,sizeof(int));
if(p3==NULL)
{
exit(1);
}
for(r=0,i=0,j=0;(i<n1)&&(j<n2);r++)
{
if(cmp(p1[i],p2[j])==1)
{
p3[r]=p2[j];
j++;
}
else
{
p3[r]=p1[i];
i++;
}
}
if(i==n1)
{
for(;j<n2;)
{
p3[r]=p2[j];
r++;
j++;
}
}
else
{
for(;i<n1;)
{
p3[r]=p1[i];
r++;
i++;
}
}
for(i=0,n1+=n2;i<n1;i++)
{
printf("%d\n",p3[i]);
}
free(p1);
free(p2);
free(p3);
return 0;
}
void input(int **p1,int *n1)
{
int i;
scanf("%d",n1);
*p1=(int *)calloc(*n1,sizeof(int));
if(*p1==NULL)
{
exit(1);
}
for(i=0;i<*n1;i++)
{
scanf("%d",*p1+i);
}
return ;
}
int cmp(int a,int b)
{
return a>=b?1:0 ;
}