Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- void bFlagSort(int data[], int n){
- bool flag;
- do{
- for(int i=0;i<n;i++){
- flag = false;
- for(int j=0;j<n-i-1;j++){
- if(data[j]>data[j+1]){
- int temp = data[j+1];
- data[j+1] = data[j];
- data[j] = temp;
- flag = true;
- }
- }
- }
- }while(flag);
- }
- void printColumn(int data[], int n, int col){
- for(int i=0;i<col;i++){
- for(int j=i;j<n;j+=col){
- if((j+col>n-1)){
- printf("%d\n", data[j]);
- }else{
- printf("%d ", data[j]);
- }
- }
- }
- }
- int main(){
- int tc, n, col;
- scanf("%d", &tc);
- for(int i=1;i<=tc;i++){
- scanf("%d %d", &n, &col);
- int data[n];
- for(int j=0;j<n;j++){
- scanf("%d", &data[j]);
- }
- bFlagSort(data, n);
- printColumn(data, n, col);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement