# include <stdio.h> # define m 100 # define n 100 char x(char r[int n][int m]) { int i,j,k; char t; for(i=0;i<n;i++) for(j=0;j<m-k;j++) { if(r[j][i]<r[j+1][i]) {t=r[j][i];r[j][i]=r[j+1][i];r[j+1][i]=t;} k++; } return x; } void main() { int i,j; char r[n][m]; for(i=0;i<m;i++) for(j=0;j<n;j++) scanf("%c",&r[j][i]); x(r); for(i=0;i<m;i++) for(j=0;j<n;j++) printf("%c",r[j][i]);
} 这是我的编码感觉很乱
最新回答
枫熙槿晨
2024-11-30 02:59:21
程序没运行,仅供参考 # include <stdio.h> # define MAX_M 100 # define MAX_N 100 void Sort(char (*r)[], int n, int m) { int i, j, k; char t; for( i = 0; i < n; i ++ ) for( j = 1; j < m; j ++) for( k = 0; k < m - j; k ++) { if( r[i][k] < r[i][k+1] ) { t = r[i][k]; r[i][k] = r[i][k+1]; r[i][k+1] = t; } } }
void main() { int i, j, n, m; char str[MAX_N][MAX_M]; scanf("%d%d", &n, &m); for(i = 0; i < n; i ++) for(j = 0; j < m; j ++) scanf( "%c", &str[i][j] ); Sort(r, n, m); for( i = 0; i < n; i ++ ) for( j = 0; j < m; j ++ ) printf( "%c", str[i][j] ); }