Mco*_*orz -1 c++ stl map std-pair
#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;
}
Run Code Online (Sandbox Code Playgroud)
我按照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'
Run Code Online (Sandbox Code Playgroud)
看看我的代码,并帮助我解决这个问题.在此先感谢您的帮助.
您需要使用std
命名空间.
无论是键入std::map
而不是在开头map
使用using std::map;
.
或者如果你真的很懒,你可以键入using namespace std;
以使用所有标准函数和类型.但要注意姓名冲突.
归档时间: |
|
查看次数: |
1201 次 |
最近记录: |