Sort Rows - Alphabets & Integer Matrix DC [30/05/2021]
Sort Rows - Alphabets & Integer Matrix
Code In C:
#include <stdio.h>
#include<stdlib.h>
int main()
{
int R,C;
scanf("%d %d\n",&R,&C);
char mat[R][C][101],arr[R],temp[R];
for(int i=0;i<R;i++)
{
for(int j=0;j<C;j++)
{
scanf("%s ",&mat[i][j]);
if(mat[i][j][0]>='a' && mat[i][j][0]<='z')
{
arr[i]=mat[i][j][0];
temp[i]=arr[i];
}
}
}
for (int i=0;i<R-1;i++){
for(int j=i+1;j<R;j++)
{
if(temp[i]>temp[j])
{
char t=temp[i];
temp[i]=temp[j];
temp[j]=t;
}
}
}
for(int i=0;i<R;i++)
{
int row=-1;
for(int j=R-1;j>=0;j--)
{
if(temp[i]==arr[j])
{
row=j;
arr[j]='-';
break;
}
}
for(int k=0;k<C;k++)
{
printf("%s ",mat[row][k]);
}
printf("\n");
}
return 0;
}
Comments
Post a Comment