gpt4 book ai didi

c++ - 在此程序中出现错误 : Checking if two array equal?

转载 作者:太空宇宙 更新时间:2023-11-04 13:03:46 25 4
gpt4 key购买 nike

在编译程序时弹出一个错误,我无法弄清楚它是什么:“没有对 _distance_fw(int&,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;
}
}
}
}
}
}

最佳答案

你只需要改变

bucket.insert(val,def)

进入:

bucket.insert({val,def})

std::unordered_map::insert需要 std::unordered_map::value_type在这种情况下是 std::pair<const int int> .

请更好地格式化您的代码。

关于c++ - 在此程序中出现错误 : Checking if two array equal?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43202900/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com