日常學習 語法 STL之set

2021-06-28 15:37:22 字數 1499 閱讀 9192

今天剛剛學習了set 在我寫這篇文章之前 請允許我首先對ty菌表示誠摯的感激 請教ty菌之前我眼裡ruka簡直不知所云tut

set是乙個集合 和康托前輩的一樣 集合中的元素不重複 且集合中的元素是有序的(自動有序化) ty菌介紹說其內部實質是乙個平衡樹

set不是陣列 只能通過迭代器(iterator)把裡面的元素倒出來 迭代器相當於是指標 掃瞄的是位址 因此輸出的時候需要用*variation

宣告:

需要用到頭檔案set

setdict; 建立乙個集合 其名為dict 基型別是string

常用函式:

dict.insert() 將括號裡的變數放到集合中

dict.begin() dict.end()返回集合最初和最後的元素的位址

這是寫這個例題用到的

在某書的最後函式附錄裡看到這些好像都是list模板函式 暫時還不清楚是怎麼回事

這次例題是uva10815 - andy's first dictionary 安迪的第乙個字典 大意是給你一段文字 把裡面的單詞按字典序排列 每個單詞只出現一次

先放**

#include#include#include#includeusing namespace std;

setdict;//set up a set called dict-short for dictionary,and it's based on string type;

int main()

for (set::iterator it=dict.begin();it!=dict.end();++it)//iterator just like a point,scan it from beginning to end and output

cout<<*it<

isalpha()判斷是否是字母 如果是就用頭tolower()轉換成小寫 否則就轉為空格 這樣是為了字串流重讀入的時候能夠把空格去掉

特別強調一下本例中出現的迭代器

for (set::iterator it=dict.begin();it!=dict.end();++it)//iterator just like a point,scan it from beginning to end and output

cout<<*it<

顯然對於set我還知之甚少 還需要在今後的學習中不斷掌握

這個寒假又是乙個繁忙的寒假 希望我在這個短暫倉促卻又溫暖充實的假期中能長進良多 

—— 漸黃昏,清角吹寒,都在空城

Linux學習 語法

語法 if then 語句 if then else 語句 if 測試條件成立 then 執行命令 elif 條件成立 then 執行命令 else 條件不成立時,執行相應命令 fi 結束 bin bash case demo case 1 in start start echo 0 start.s...

日常學習 STL之map

對map最初的印象,源於王建德老師在山東noip夏令營上那銷魂的一句 map,i,j 音 嘜頗,挨,傑 ruka上對map並沒有講很多,ty菌說map主要用來寫雜湊 雖然她曾用它寫過鄰接矩陣 迴圈巢狀map intorz 而李晨和里奧甚至表示基本不用map。但是既然有這一項奇妙的東西,想必是有用的,...

STL學習之set容器

set容器只是單純的鍵的集合。除了兩種例外情況外,set容器支援大部分的map操作。建構函式 cpp view plain copy explicit set const compare comp compare const allocator allocator template class in...