This repository has been archived by the owner on Jun 20, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 33
/
Copy pathC_Jay_Patel.c
86 lines (80 loc) · 1.4 KB
/
C_Jay_Patel.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
79
80
81
82
83
84
85
86
#include <stdio.h>
int main() {
char n1[201]={}, n2[201]={}, merge[401]={};
scanf("%s\n%s",n1,n2);
int i = 0, j = 0, k = 0;
while(n1[i] != '\0' && n2[j] != '\0') {
if(n1[i] > n2[j]) {
merge[k] = n1[i];
i++;
k++;
} else if(n1[i] < n2[j]){
merge[k] = n2[j];
j++;
k++;
} else {
int l1 = i+1, l2 = j+1, check = 0;
while(n1[l1] != '\0' && n2[l2] != '\0') {
if(n1[l1] == n2[l2]) {
l1++, l2++;
continue;
} else if(n1[l1] > n2[l2]) {
check = 1;
merge[k] = n1[i];
i++;
k++;
break;
} else {
check = 1;
merge[k] = n2[j];
j++;
k++;
break;
}
}
if(check == 0) {
if(n1[l1] == '\0' && n2[l2] == '\0') {
while(n1[i] != '\0') {
merge[k] = n1[i];
i++;
k++;
}
while(n2[j] != '\0') {
merge[k] = n2[j];
j++;
k++;
}
break;
}
else if(n1[l1] == '\0' && n2[l2] >= n2[j]) {
merge[k] = n2[j];
j++;
k++;
} else if(n2[l2] == '\0' && n1[l1] >= n1[i]) {
merge[k] = n1[i];
i++;
k++;
} else if(n2[l2] == '\0' && n1[l1] < n1[i]) {
merge[k] = n2[j];
j++;
k++;
} else if(n1[l1] == '\0' && n2[l2] < n2[j]) {
merge[k] = n1[i];
i++;
k++;
}
}
}
}
while(n1[i] != '\0') {
merge[k] = n1[i];
i++;
k++;
}
while(n2[j] != '\0') {
merge[k] = n2[j];
j++;
k++;
}
printf("%s",merge);
}