Quantcast
Channel: CodeChef Discuss - latest questions
Viewing all articles
Browse latest Browse all 40121

knight move problem(there is a wrong sign showing in code but i cant figure out)

$
0
0

knight move problem(there is a wrong sign showing in code but i cant figure out) the code is

include<cstdio>

include<algorithm>

include<string.h>

include <cstdlib>

using namespace std;

int valid(char *); int main() {

    int n;
    scanf("%d",&n);
    char move[13];
    int flag;
    int x,y;
    for(int i=0;i<n;i++){
        scanf("%s",move);
        if(valid(move)){
            x=abs(move[0]-move[3]);
            y=abs(move[1]-move[4]);
            if((x==1 && y==2) || (x==2 && y==1) ){
                flag=1;
            }
            else flag=0;
            if(flag)printf("Yes\n");
            else printf("No\n");
        }
        else{
            printf("Error\n");
            }


        }

         return 0;
    }



int valid(char x[]){

    if(strlen(x)==5 && x[2]=='-'){
        if(x[0]>96 && x[0]<105 && x[3]>96 && x[3]<105 && x[1]>48 && x[1]<57 && x[4]>48 && x[4]<57)
            {return 1;}}
     return 0;
    }

Viewing all articles
Browse latest Browse all 40121

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>