| # | Problem | Pass Rate (passed user / total user) |
|---|---|---|
| 10878 | Array sort_row |
|
Description
Given two dimensional array of size M x N(1 < M,N < 10).
We want to sort separately for each row of the two dimensional array value
For example:
|
5 |
1 |
3 |
11 |
25 |
|
45 |
82 |
97 |
73 |
63 |
|
13 |
47 |
34 |
26 |
14 |
After sorted
|
1 |
3 |
5 |
11 |
13 |
|
45 |
63 |
73 |
82 |
97 |
|
13 |
14 |
26 |
34 |
47 |
Submit only your function.c into the submission block. (Please choose C compiler)
The bubble sort algorithm:
/* Using bubble sort to rearrange an array A[n] */
for (i = 0; i < n; i++) {
for (j = 1; j < n - i; j++) {
if (A[j-1] > A[j]) {
/* swap A[j-1] A[j] */
}
}
}
main.c
#include <stdio.h>
#include "function.h"
int main()
{
int M,N;
int i,j;
scanf("%d%d", &M, &N);
int array[M][N];
for(i = 0; i < M; i++)
for(j = 0; j < N; j++)
scanf("%d", &array[i][j]);
sortArray( M, N, array);
printResult( M, N, array);
return 0;
}
function.h
void swap(int *a, int *b);
void sortArray(int M, int N, int (*array)[N]);
void printResult(int M, int N, int (*array)[N]);
Input
The first line is two dimensional array size M and N.(1 <M,N <10)
The other line are value of array to be sorted.
Output
Each line shows output of sorted array.
All of the integers in the same line are separated by a space, and there is a '\n' at the end of each line.