#include<stdio.h>
#include<map>
int main()
{
int cases, i, j, act, answer, min_ind, min_val, temp1, temp2;
scanf("%d",&cases);
for(i=0; i<cases; i++)
{
answer = 0;
scanf("%d", &act);
map<int, int> mymap;
for(j=0; j<act; j++)
{
scanf("%d",&temp1);
scanf("%d",&temp2);
mymap[temp2] = temp1;
}
map<int,int>::iterator it = mymap.begin();
temp1 = it->second;
while(mymap.size() != 0)
{
it = mymap.begin();
if(it->second < temp1)
{
mymap.erase(it);
continue;
}
answer++;
temp1 = it->first;
mymap.erase(mymap.begin());
if(mymap.size() != 0)
{
it = mymap.begin();
while(it->second < temp1)
{
mymap.erase(it);
it = mymap.begin();
}
}
}
printf("%d\n",answer);
}
return 0;
}
我已根据C ++的STL包含了映射头,但仍然没有编译并给出编译错误。我试过包含map.h头文件,但仍然得到相同的错误
错误:
prog.cpp: In function 'int main()':
prog.cpp:13: error: 'map' was not declared in this scope
prog.cpp:13: error: expected primary-expression before 'int'
prog.cpp:13: error: expected `;' before 'int'
prog.cpp:19: error: 'mymap' was not declared in this scope
prog.cpp:22: error: expected primary-expression before 'int'
prog.cpp:22: error: expected `;' before 'int'
查看我的代码并帮助我解决这个问题。感谢您提前提供任何帮助。
答案 0 :(得分:6)
您需要使用std
命名空间。
键入std::map
代替map
或在开头使用using std::map;
。
或者,如果你真的很懒,可以输入using namespace std;
来使用所有标准函数和类型。但要注意姓名冲突。
答案 1 :(得分:2)
它位于std
命名空间中,因此您需要对其进行限定:std::map
。
答案 2 :(得分:2)
它被称为std::map
。您需要限定namespace。
如果您在程序顶部附近写了using namespace std;
,那么您不必这样做,我实际上不建议。