here is only basic implementation of problems for beginners. If you have any problem with any solution or any basic concept of programming or you want more efficient solution you can mail me.
my suggestion is not to copy and paste codes from here try to understand the logic and think why you were not able to solve it.

Tuesday, 9 June 2015

Traversing Grid

problem statement is here



#include<stdio.h>
int main(){
    long long int n,m;
    int t;
    scanf("%d",&t);
    while(t--){
        scanf("%lld %lld",&n,&m);
        if(n%2==0 && m%2==0){
            if(n>m){
            printf("U\n");
            }else if(m>=n)
                    printf("L\n");
        }
        else if(n%2!=0 && m%2!=0){
            if(n>m)
                printf("D\n");
            else if(m>=n)
                printf("R\n");
        }
        else{
            if(n%2==0 && m%2!=0)
                {
                    if(n>m)
                        printf("D\n");
                    else
                        printf("L\n");
                }
            if(n%2!=0 && m%2==0)
                {
                    if(n<m)
                        printf("R\n");
                    else
                        printf("U\n");
                }
        }
    }
    return 0;
}

No comments:

Post a Comment