输入二维数组,每行从小到大排序
例,输入;
2 4
1 4 2 3
9 6 8 7
输出:
1 2 3 4
6 7 8 9
#include<cstdio>
#include<algorithm>
using namespace std;
const int maxsize=100;
bool cmp(int a,int b)
{return a<b;
}
int main()
{
int n,m;
int a[maxsize][maxsize];
scanf("%d%d",&n,&m);
for(int i=0;i<n;i++)
{
for(int j=0;j<m;j++)
{scanf("%d",&a[i][j]);
}
}
int i=0;
while(i<n)
{
int b[m]={};
for(int j=0;j<m;j++)
{
b[j]=a[i][j];
}
for(int j=0;j<m;j++)
{
sort(b,b+m,cmp);
printf("%d",b[j]);
}
i++;
printf("\n");
}
return 0;
}