STL容器(map) HDU例題

2021-08-05 20:15:37 字數 2081 閱讀 2484

map 的使用  注意first 為key值  second 是value值

然後就是在杭電上頭檔案對於map的map::iterator i;的操作。使用#include會編譯錯誤。。則不會

對於hdu1263,由於map儲存是按key值的字母順序排序,所以這裡免去了排序的步驟。

stl很強大!

hdu1004:

[cpp]view plain

copy

print?

#include

#include

#include

using

namespace std;  

mapint>m;  

mapint>::iterator p,q;  

int n;  

int main()  

int k=-1;  

for(p=m.begin();p!=m.end();p++)   //查詢

}  coutreturn 0;  

}  

#include#include#includeusing namespace std;

mapm;

map::iterator p,q;

int n;

int main()

int k=-1;

for(p=m.begin();p!=m.end();p++) //查詢

}cout然後是hdu1075

[cpp]view plain

copy

print?

#include 

#include 

#include 

#include

#include

using

namespace std;  

mapm;  

map::iterator it;  

char c[3020];  

int main()  

scanf("%s",s);  

getchar();  

while(gets(c))  

else

else

printf("%c",c[i]);  

j=0;  

}  }  

printf("\n");  

}  return 0;  

}  

#include #include #include #include#includeusing namespace std;

mapm;

map::iterator it;

char c[3020];

int main()

scanf("%s",s);

getchar();

while(gets(c))

else

else

printf("%c",c[i]);

j=0;}}

printf("\n");

}return 0;

}

最後hdu1263

[cpp]view plain

copy

print?

#include

#include

#include

#include

using

namespace std;  

int main()  

for(i=a.begin();i!=a.end();i++)  

}  if(t!=0)  

printf("\n");  

}  }  

#include#include#include#includeusing namespace std;

int main()

for(i=a.begin();i!=a.end();i++)

{coutfor(j=b.begin();j!=b.end();j++)

{cout<<" |----"

C 容器(STL容器)

容器 container 用於存放資料的類模板。可變長陣列 鍊錶 平衡二叉樹等資料結構在stl中都被實現為容器。在使用容器時,即將容器類模型例項化為容器類,會指明容器中存放的元素是什麼型別。容器可以分為兩大類 順序容器和關聯容器 順序容器有可變長動態陣列vector 雙端佇列deque 雙向鍊錶li...

stl容器之順序容器

stl容器分為順序容器和關聯容器 其中順序容器最常用的由vector,list,queue 1.vector vector 向量容器,可以看作變長陣列,長度可根據需要自行變化。使用的標頭檔案 include 定義方式 vector陣列名 vectorar 訪問容器內資料的方式和普通陣列相同,可以用a...

STL容器簡介

stl的容器可以分為以下幾個大類 一 序列容器,有vector,list,deque,string.二 關聯容器,有set,multiset,map,mulmap,hash set,hash map,hash multiset,hash multimap 三 其他的雜項 stack,queue,va...