Adrita

lab 6(lexographical

May 4th, 2019
180
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.56 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<string.h>
  3. int main()
  4. {
  5.     int n,j,i;
  6.     scanf("%d",&n);
  7.     char str[100][100],temp[100];
  8.     for(i=0;i<n;i++)
  9.     {
  10.         scanf("%s",str[i]);
  11.     }
  12.     for(i=0;i<n-1;i++)
  13.     {
  14.         for(j=0;j<n-1-i;j++)
  15.         {
  16.             if(strcmp(str[j],str[j+1])>0)
  17.                {
  18.                    strcpy(temp,str[j]);
  19.                    strcpy(str[j],str[j+1]);
  20.                    strcpy(str[j+1],temp);
  21.                }
  22.         }
  23.     }
  24.     for(i=0;i<n;i++)
  25.        {
  26.            printf("%s\n",str[i]);
  27.        }
  28. }
Advertisement
Add Comment
Please, Sign In to add comment