lundi 5 août 2019

Why two vector pair can not be compared

I am using two vector pair in my code but can not compare the first value of the first vector to the first value of the second vector and so on.In my code I initialize vector v to take the input from the main function and then use nqueen function to initialize vector com.Now I can not compare both the vectors

int queen[20], cnt = 0;
int diagonal1[20], diagonal2[20], column[20];
void nqueen (int at, int n,vector<int>& v) {
   if (at == n+1) {
      vector<pair<int,int>>com;
      bool flag=true;
      for (int i = 1; i <= n; i++) {
        com.pb(mp(i,queen[i]));
      }
      for(int i=1; i<=8 ; ++i)
      {
        if((v[i].first==com[i].first)&&(v[i].second==com[i].second)) flag=false;
      }
      v.clear();
      cout<<(flag==true?"Invalid":"Valid");
      printf ("\n");
   }
   for (int i = 1; i <= n; i++) {
      if (column[i] || diagonal1[at+i] || diagonal2[n+at-i]) continue;
      queen[at] = i;
      column[i] = diagonal1[at+i] = diagonal2[n+at-i] = 1;
      nqueen (at+1, n);
      column[i] = diagonal1[at+i] = diagonal2[n+at-i] = 0;
   }
}

I am having the error massage::

[Error] request for member 'first' in '(& v)->std::vector<_Tp,
_Alloc>::operator[]<int, std::allocator<int> >(((std::vector<int>::size_type)i))', which is of non-class type '__gnu_cxx::__alloc_traits<std::allocator<int> >::value_type {aka
int}'

Aucun commentaire:

Enregistrer un commentaire