Advertisement
cbmelo97

Untitled

Sep 9th, 2018
3,208
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <stdio.h>
  2.  
  3. short main(){
  4.     short n;
  5.     scanf("%hi", &n);
  6.  
  7.     while(n--){
  8.         short m, c;
  9.         scanf("%hi %hi", &m, &c);
  10.         short matriz[m][c];
  11.  
  12.         for(short i = 0; i<m; i++){
  13.             for(short j = 0; j<c; j++){
  14.                 matriz[i][j]=0;
  15.             }
  16.         }
  17.  
  18.         for(short i = 0; i<c; i++){
  19.             short cValor, hash;
  20.             scanf("%hi", &cValor);
  21.  
  22.             hash = cValor % m;
  23.             for(short i = 0; i<c; i++){
  24.                 if(matriz[hash][i] == 0){
  25.                     matriz[hash][i] = cValor;
  26.                     break;
  27.                 }
  28.             }
  29.         }
  30.        
  31.         for(short i = 0; i < m; i++){
  32.             printf("%hi -> ", i);
  33.             for(short j = 0; j<c; j++){
  34.                 if(matriz[i][j] == 0){
  35.                     break;
  36.                 } else {
  37.                     printf("%hi -> ", matriz[i][j]);
  38.                 }
  39.             }
  40.             printf("\\\n");
  41.         }
  42.                
  43.         if(n) {
  44.             printf("\n");
  45.         }
  46.     }
  47.     return 0;
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement