DCP-4: Great!!! The Work Is Done Solution

code i tried  around 5 of hours but didn’t succeded:

#include<stdio.h>
#include<math.h>
int main()
{
    int t,n,i,result,p,sum=0;
    while(scanf("%d %d",&t,&n)==2)
    {
        for(i=0; i<n; i++)
        {
            scanf("%d",&p);
            sum=sum+p;
        }
        //if(sum<=24)

        double check=t/(0.5*t);
        double divcheck=(double)t/sum;
        printf("%lf\n",check);
        printf("%lf\n",divcheck);
        if(check==divcheck)
        {
            result=t/sum;
            if(result==1)
            {
                printf("Project will finish within %d day.\n",result);
            }
            else
            {
                printf("Project will finish within %d days.\n",result);
            }
        }
        else if(sum<t)
        {
            if(sum==check)
            {
                result=t/sum;
                printf("Project will finish within %d days.\n",result);
            }
            else
            {
                result=t/sum;
                printf("Project will finish within %d days.\n",result+1);
            }
        }
        else if(sum==t)
        {
            result=t/sum;
            printf("Project will finish within %d day.\n",result);
        }
        else if(sum>t)
        {
            result=t/sum;
            printf("Project will finish within %d day.\n",result+1);
        }
        sum=0;
    }
    return 0;
}

 

after checking one solution in github repo found the logic and impelmented in my own:
code:

#include<stdio.h>
int main()
{
    int t,n,p,i,result,sum;

    while(scanf("%d %d",&t,&n)!=EOF)
    {
        sum=0;
        for(i=0; i<n; i++)
        {
            scanf("%d",&p);
            sum=sum+p;
        }
        result=0;
        if(t%sum==0) //mod diyei onek somosshar somadhan hoye jay eta sobshomoy mathay rakhte hobe
        {
            result=t/sum; //if it is divisible then we can just divide it to get the result as per test case
        }
        else
        {
            result=(t/sum)+1; //as we are finding point value so we need to add 1 to get the accurate integer
        }

        if(result==1)
        {
            printf("Project will finish within 1 day.\n"); //as per output
        }
        else
        {
            printf("Project will finish within %d days.\n",result);  //as per output
        }
    }
    return 0;
}

uDebug also helped me for critical case:
https://www.udebug.com/DS/4

It would be a great help, if you support by sharing :)
Author: zakilive

Leave a Reply

Your email address will not be published.