COOLING: Need help

#include<stdio.h>
int main()
{ int t ,n,k[100],i,p[100],g,j,l,a,b;
scanf("%d",&t);
while(t>0)
{ int f=0;
scanf("%d",&n);
for(i=0;i<n;i++)
{scanf("%d",&g);
k[i]=g;}
for(j=0;j<n;j++)
{scanf("%d",&l);
p[j]=l;}

for(a=0;a<n;a++)
{
for(b=0;b<n;b++)
{
for(b=0;b<n;b++)
{if(p[a]=k[b])
{p[a]=0;k[b]=0;f++;b++;}
}
                
if(p[a]>k[b]&&k[b]!=0)
{f++; k[b]=0;p[a]=0;}

}
}
printf("%d",f);
t--;
}
return(0);
}

what’s your question ? please explain the logic you used to solve it.

1 Like

well i used the logic that once a pie and a wieghts are used they are not to be considerd again so make them zero and hence i put a test condoition of k[pie]!=0 and for max efiiciency i first looked for pie wieght= wight of pie holder thats the logic

When compiling your code use -Wall (show all warning option) for example:

g++-4 -Wall -g cooling.cpp -o cooling.exe

output is

cooling.cpp: In function 'int main()':
cooling.cpp:15:18: warning: suggest parentheses around assignment used as truth value

and I assume you do NOT want to use assignment in if

if(p[a]=k[b]) {p[a]=0;k[b]=0;f++;b++;}

Your solution stil fails to solve input from statement.

NOTE: in my opinion, it would be nice if you count++ inversely. assume weight is X, and limit is Y func respectively. we have(or reach) our desired count++ when Y’s element is bigger than or equal to X’s particular element. and in that condition we count++. otherwise, we just pass onto Y’s next element, till we meet the condition.