Advertisement
Guest User

Untitled

a guest
Mar 24th, 2019
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.11 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. int main()
  4. {
  5. int q_teste, q_end, q_chaves, chave, end, end_ant;
  6. int g = 0;
  7.  
  8. scanf("%d", &q_teste);// numero de testes q serão feitos
  9.  
  10.  
  11. for(int i = 0; i<q_teste; i++){//for para armazenar os testes
  12.  
  13. scanf("%d %d", &q_end, &q_chaves);// recebe quantidade de endereços e chaves
  14.  
  15. int v[q_end][q_chaves];// cria a matriz com o tramanho do endereço e das chaves
  16.  
  17. for(int a = 0; a<q_end; a++){// zera toda a matriz
  18.  
  19. for(int b = 0; b<q_chaves; b++){
  20.  
  21. v[a][b] = 0;
  22. }
  23. }
  24.  
  25. for(int f = 0; f<q_chaves; f++){/* recebe as chaves de acordo com
  26. o tamanho de chaves pedido*/
  27.  
  28. scanf("%d", &chave);
  29.  
  30. end = chave % q_end;// hash função, vai dar um endereço
  31.  
  32. if(end_ant != end){/* zera G toda vez que o
  33. endereço for diferente que o endereço anterior*/
  34.  
  35. g = 0;
  36. }
  37.  
  38. end_ant = end;// armazena no endereo como anterior
  39.  
  40. while(v[end][g]!=0){// tratamento de colisão
  41. g++;
  42. }
  43. v[end][g]= chave;
  44. }
  45. for(int n = 0; n<q_end; n++){// condições do print, for da linha
  46.  
  47. printf(" %d", n);
  48.  
  49. for(int m = 0; m<q_chaves; m++){// for da coluna
  50.  
  51. if (v[n][m] != 0){ /* printa isso se existir um
  52. valor na posião da matriz*/
  53.  
  54. printf(" -> %d", v[n][m]);
  55.  
  56. if(m == q_chaves - 1){
  57.  
  58. printf(" -> \\");
  59. printf("\n");
  60. }
  61.  
  62. }
  63.  
  64. else{
  65.  
  66. printf(" -> \\");// printa / se for vazio
  67. printf("\n");
  68. break;
  69. }
  70.  
  71. }
  72. }
  73. if(i < q_teste - 1){/*pula linha duas vezes ao
  74. final da matriz antes do ultimo teste*/
  75.  
  76. printf("\n");
  77. }
  78. }//fecha o for dos testes
  79. return 0;
  80. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement