2017-04-04 26 views
1

儘管編譯錯誤時彈出的程序,我無法弄清楚它是什麼:「不匹配的函數調用_distance_fw(INT &,詮釋&)」。 在這裏,在這個問題中,我試圖檢查兩個數組是否在它們包含的值方面相等。在這個程序中獲取錯誤:檢查兩個數組是否相等?

#include<iostream> 
#include<algorithm> 
#include<unordered_map> 

using namespace std; 

unordered_map<int,int> bucket; 
unordered_map<int,int>::const_iterator it; 

int main() 
{ 
    int T,N,val,counter; 
    int def=1; 
    bool bug; 
    scanf("%d",&T); 
    { 
     for(int i=0;i<T;i++) 
     { 
      scanf("%d",&N); //N is the size of array 
      counter=N; 
      bucket.erase(bucket.begin(),bucket.end()); 
      for(int j=0;j<2;j++) 
      //scanning the first array 
      { 
       while(counter>0) 
       { 
        if(j==0) 
        { 
         scanf("%d",&val); 
         it=bucket.find(val); 
         if(it==bucket.end()) 
         { 
          bucket.insert(val,def); 
         } 
         else 
         { 
          bucket[val]++; 
         } 
        } 
        else 
        { 
         scanf("%d",&val); 
         it=bucket.find(val); 
         if(it!=bucket.end()) 
         { 
          bucket[val]--; 
         } 
         else 
         { 
          bug=true; 
         } 
        } 
        counter--; 
       } 
       if(bug==true) 
       { 
        cout<<"0"<<endl; 
       } 
       else 
       { 
        for(it=bucket.begin();it!=bucket.end();it++) 
        { 
         if(it->second!=0) 
         { 
          cout<<"0"<<endl;bug=true;break; 
         } 
        } 
        if(bug==false) 
        { 
         cout<<"1"<<endl; 
        } 
       } 
      } 
     } 
    } 
} 
+1

您可以與我們分享導致此特定縮進/格式化方案的決策過程嗎? –

回答

0

你只需要改變

bucket.insert(val,def) 

分爲:

bucket.insert({val,def}) 

std::unordered_map::insert需要一個std::unordered_map::value_type在這種情況下是std::pair<const int int>

並請更好地格式化您的代碼。

+0

謝謝,這很有幫助! –