Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include<string.h>
- int main()
- {
- int i,j,k,n;
- char a[1100][30], temp[30];
- scanf("%d",&n);
- for(i=0;i<n;i++)
- {
- scanf("%s",a[i]);
- }
- for(i=0;i<n;i++)
- {
- for(j=0;j<n-i;j++)
- {
- for(k=0;a[j][k]!='\0';k++)
- {
- if(a[j][k]>a[j+1][k])
- {
- strcpy(temp,a[j]);
- strcpy(a[j],a[j+1]);
- strcpy(a[j+1],temp);
- break;
- }
- if(a[j][k]==a[j+1][k])
- {
- continue;
- }
- if(a[j][k]<a[j+1][k])
- {
- break;
- }
- }
- }
- }
- for(i=0;i<n;i++)
- {
- printf("%s\n",a[i]);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement