-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstring_comp.c
67 lines (66 loc) · 1.02 KB
/
string_comp.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
#include <stdio.h>
#include <string.h>
int comp(char s1[],char s2[])
{
int i=0;
while(s1[i]!='\0')
{
if(s2[i]=='\0')
return s1[i]-s2[i];
else if(s1[i]!=s2[i])
return s1[i]-s2[i];
i++;
}
return 0;
}
void swap(char s1[],char s2[])
{
char temp[100];
int i=0;
while(s1[i]!='\0')
{
temp[i]=s1[i];i++;
}
temp[i]='\0';
i=0;
while(s2[i]!='\0')
{
s1[i]=s2[i];i++;
}
s1[i]='\0';
i=0;
while(temp[i]!='\0')
{
s2[i]=temp[i];i++;
}
s2[i]='\0';
return;
}
int main()
{
int n;
scanf("%d",&n);
char ch[n][100];
int i,j;
for(i=0;i<n;i++)
{
scanf("%s",ch[i]);
}
for(i=0;i<n-1;i++)
{
for(j=0;j<n-1;j++)
{
int k=comp(ch[j],ch[j+1]);
if(k>0)
{
char s[100];
swap(ch[j],ch[j+1]);
}
}
}
for(i=0;i<n;i++)
{
printf("%s ",ch[i]);
}
return 0;
}