Showing posts with label Strange Grid Again Hacker Rank Solution in C. Show all posts
Showing posts with label Strange Grid Again Hacker Rank Solution in C. Show all posts

Monday, 1 July 2019

Constructing a Number Hacker Rank Solution in C, Strange Grid Again Hacker Rank Solution in C, Points on a Line Hacker Rank Solution in C

Strange Grid Again

https://www.hackerrank.com/challenges/strange-grid/problem

#include <stdio.h>
int main()
{
    unsigned long long int r,c;
    scanf("%llu%llu",&r,&c);
    if(r%2 == 0)
    {
        unsigned long long int term = ((r-1)/2)*5+c;
        printf("%llu",2*term-1); // nth term in odd series = 2*n-1
    }
    else{
        unsigned long long int term = ((r)/2)*5+c;
        printf("%llu", 2*term-2); // nth term in even series = 2*n-2
    }
    return 0;
}

Points on a Line


#include <stdio.h>
int main()
{
    int t;
    scanf("%d",&t);
    int x,y,res=0;
    scanf("%d%d",&x,&y);
    t--;
    while(t--)
    {
        int t1,t2;
        scanf("%d%d",&t1,&t2);
        if(!(t1 == x || t2 == y))
            res=1;

    }
    if(res == 1)
        printf("NO");
    else
        printf("YES");
}


Constructing a Number 


https://www.hackerrank.com/challenges/constructing-a-number/problem


Function:
char* canConstruct(int a_count, int* a)
 {
   
              long long int i,sum=0;
              for(i=0;i<a_count;i++)
                          sum=sum+a[i];
              if(sum%3 == 0)
                          return "Yes";
              return "No";
}