lundi 23 décembre 2019

Why is this code not working?Help me solve Errors

int bounds(int x,int y,int n)
{
    if((x>=1 && x<=n)&&(y>=1 && y<=n)) return 1;
    else return 0;
}
// Complete the queensAttack function below.
int queensAttack(int n, int k, int r_q, int c_q, vector<vector<int>> obstacles) 
{
    int dx[]={1,-1,0,0,1,-1,1,-1};
    int dy[]={0,0,1,-1,1,-1,-1,1};
    vector<int>temp;
    //std::vector<int>::iterator it;
    int _x=r_q,_y=c_q,count=0,f=1;
    for (int i=0;i<8;i++)
    {
        while(f)
        {
            _x=r_q+dx[i];
            _y=c_q+dy[i];
            if(bounds(_x,_y,n))
            {
                temp.push_back(_x);
                temp.push_back(_y);
                std::vector<int>::iterator it = std::find (obstacles.begin(),obstacles.end(),temp);
                if(it != obstacles.end()) f=0;
                else count++;
            }
            else f=0;
        }
        f=1;
    }
    return count;
}

2 Errors:-

Solution.cpp: In function ‘int queensAttack(int, int, int, int, std::vector<std::vector<int> >)’:
Solution.cpp:29:59: error: conversion from ‘__normal_iterator<std::vector<int>*,vector<std::vector<int>>>’ to non-scalar type ‘__normal_iterator<int*,vector<int>>’ requested
                 std::vector<int>::iterator it = std::find (obstacles.begin(),obstacles.end(),temp);
                                                 ~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Solution.cpp:30:23: error: no match for ‘operator!=’ (operand types are ‘std::vector<int>::iterator’ {aka ‘__gnu_cxx::__normal_iterator<int*, std::vector<int> >’} and ‘std::vector<std::vector<int> >::iterator’ {aka ‘__gnu_cxx::__normal_iterator<std::vector<int>*, std::vector<std::vector<int> > >’})
                 if(it != obstacles.end()) f=0;

Aucun commentaire:

Enregistrer un commentaire