Thursday, 27 August 2020

Jumping on the Clouds: Revisited Hacker Rank Solution in C

 #include<stdio.h>

int main()
{
    int n,k;
    scanf("%d%d",&n,&k);
    int c[n],ans=100;
    for(int i=0;i<n;i++)
        scanf("%d",&c[i]);
    if(c[0] == 1)
        ans=ans-3;
    else 
        ans=ans-1;
    for(int i=k;i!=0;i=(i+k)%n)
    {
        if(i%n == 0)
            break;
        if(c[i%n] == 1)
            ans=ans-3;
        else
            ans=ans-1;
    }
    printf("%d",ans);
}

No comments:

Post a Comment