Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*Sergi Castellsague
- */
- #include <stdio.h>
- #include <string.h>
- #define TRUE 1
- #define FALSE 0
- void llegirDades(int *pesMaxim, int *participants, int pes[]){
- int i=0;
- scanf("%d",pesMaxim);
- scanf("%d",participants);
- for (i = 0; i < *participants; i++){
- scanf("%d",&pes[i]);
- }
- }
- void buscarPesat(int pes[], int *pesat, int participants){
- int i, trobat=FALSE, posicio;
- *pesat=0;
- for (i = 0; i < participants; i++){
- if (pes[i]>*pesat){
- *pesat=pes[i];
- posicio=i;
- //pes[i]=0;
- //trobat=TRUE;
- }
- }
- pes[posicio]=0;
- }
- int buscarParella(int pes[], int pesat, int *parella, int participants, int pesMaxim){
- int i, limitPes=0, trobat=FALSE, relacionat=0;
- limitPes=pesMaxim-pesat;
- while (relacionat==0){
- for (i = 0; (i < participants) && (trobat==FALSE); i++){
- if (pes[i]==limitPes){
- relacionat=pes[i];
- pes[i]=0;
- trobat=TRUE;
- }
- }
- limitPes--;
- if (limitPes<=0){
- relacionat=-1;
- }
- }
- return trobat;
- }
- int main (void){
- int pesMaxim, participants, pes[30000], canoes=0, i, desemparellats=0, pesat=0, parella, tenimParella=FALSE, continuar=TRUE, contador=0, k=0;
- llegirDades(&pesMaxim, &participants, pes);
- for (i = 0; i < participants && continuar==TRUE; i++){
- contador=0;
- for (k=0; k<participants; k++){
- if (pes[k]==0) contador++;
- if (contador==participants) continuar=FALSE;
- }
- if (continuar==TRUE){
- buscarPesat(pes, &pesat, participants);
- tenimParella=buscarParella(pes, pesat, &parella, participants,pesMaxim);
- canoes++;
- }
- }
- printf("%d\n",canoes);
- return 0;
- }
Add Comment
Please, Sign In to add comment