Guest User

Untitled

a guest
Jul 18th, 2018
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.58 KB | None | 0 0
  1. /*Sergi Castellsague
  2. */
  3.  
  4. #include <stdio.h>
  5. #include <string.h>
  6.  
  7. #define TRUE 1
  8. #define FALSE 0
  9.  
  10. void llegirDades(int *pesMaxim, int *participants, int pes[]){
  11. int i=0;
  12. scanf("%d",pesMaxim);
  13. scanf("%d",participants);
  14. for (i = 0; i < *participants; i++){
  15. scanf("%d",&pes[i]);
  16. }
  17. }
  18.  
  19. void buscarPesat(int pes[], int *pesat, int participants){
  20. int i, trobat=FALSE, posicio;
  21. *pesat=0;
  22. for (i = 0; i < participants; i++){
  23. if (pes[i]>*pesat){
  24. *pesat=pes[i];
  25. posicio=i;
  26. //pes[i]=0;
  27. //trobat=TRUE;
  28. }
  29. }
  30. pes[posicio]=0;
  31. }
  32.  
  33. int buscarParella(int pes[], int pesat, int *parella, int participants, int pesMaxim){
  34. int i, limitPes=0, trobat=FALSE, relacionat=0;
  35. limitPes=pesMaxim-pesat;
  36. while (relacionat==0){
  37. for (i = 0; (i < participants) && (trobat==FALSE); i++){
  38. if (pes[i]==limitPes){
  39. relacionat=pes[i];
  40. pes[i]=0;
  41. trobat=TRUE;
  42. }
  43. }
  44. limitPes--;
  45. if (limitPes<=0){
  46. relacionat=-1;
  47. }
  48. }
  49. return trobat;
  50. }
  51.  
  52. int main (void){
  53. int pesMaxim, participants, pes[30000], canoes=0, i, desemparellats=0, pesat=0, parella, tenimParella=FALSE, continuar=TRUE, contador=0, k=0;
  54.  
  55. llegirDades(&pesMaxim, &participants, pes);
  56.  
  57. for (i = 0; i < participants && continuar==TRUE; i++){
  58. contador=0;
  59. for (k=0; k<participants; k++){
  60. if (pes[k]==0) contador++;
  61. if (contador==participants) continuar=FALSE;
  62. }
  63. if (continuar==TRUE){
  64. buscarPesat(pes, &pesat, participants);
  65. tenimParella=buscarParella(pes, pesat, &parella, participants,pesMaxim);
  66. canoes++;
  67. }
  68. }
  69.  
  70. printf("%d\n",canoes);
  71.  
  72. return 0;
  73.  
  74. }
Add Comment
Please, Sign In to add comment