Problem link:
This is the easy simulation of problem. just make the sum of 'e' and 'f' and play loop till (sum>=cost)
then do temp=sum/cost and answer+=sum then sum%=cost and now sum+=sum
if you don't understand after try then only see the code otherwise you can't improve in programming
#include<stdio.h>
int main()
{
int e,f,c,i,j,n,t,s,sum,r;
scanf("%d",&t);
for(i=1;i<=t;i++)
{
sum=0;
scanf("%d %d %d",&e,&f,&c);
n=e+f;
while(n>=c)
{
s=n/c;
sum+=s;
n%=c;
n+=s;
}
printf("%d\n",sum);
}
return 0;
}
This is the easy simulation of problem. just make the sum of 'e' and 'f' and play loop till (sum>=cost)
then do temp=sum/cost and answer+=sum then sum%=cost and now sum+=sum
if you don't understand after try then only see the code otherwise you can't improve in programming
#include<stdio.h>
int main()
{
int e,f,c,i,j,n,t,s,sum,r;
scanf("%d",&t);
for(i=1;i<=t;i++)
{
sum=0;
scanf("%d %d %d",&e,&f,&c);
n=e+f;
while(n>=c)
{
s=n/c;
sum+=s;
n%=c;
n+=s;
}
printf("%d\n",sum);
}
return 0;
}
No comments:
Post a Comment