数据结构总结之map

来源:互联网 发布:ubuntu修改grub启动项 编辑:程序博客网 时间:2024/05/16 20:27

1.map

#include <iostream>#include <map>using namespace std;map<int,int> hash;int main(){    int a,b,c,d,e;    int i,j,k;    cin>>a>>b>>c>>d>>e;    for(i=-50;i<=50;i++)        for(j=-50;j<=50;j++)    {        if(i==0 || j==0) continue;        int temp=a*i*i*i+b*j*j*j;        if(hash.find(temp)!=hash.end())            hash[temp]++;        else            hash[temp]=1;    }    long long count=0;    for(i=-50;i<=50;i++)        for(j=-50;j<=50;j++)        for(k=-50;k<=50;k++)    {        if(i==0 || j==0 || k==0) continue;        int temp=-(c*i*i*i+d*j*j*j+e*k*k*k);        if(hash.find(temp)==hash.end()) continue;            count+=hash[temp];    }    cout<<count;    return 0;}

2.map.end()返回的迭代器it,要自减一次,才是map最后一个;
map.erase()、map.empty()、map.clear()
map的迭代器有first、second,用”->”,不用”.”
3.char tmp[]=”22233344455566677778889999”;这一步很巧妙,虽然经常用~