刷題知識點

2022-09-03 23:48:12 字數 2238 閱讀 8550

加速輸入輸出流,放到**頭部

static

const auto __speedup_ =()();

陣列初始化容器

int a = ;

vector

b(begin(a), end(a));

map操作

#include#include

using

namespace

std;

int main(void

)

else

//刪除

//iterator erase(iterator it);

//通過乙個條目物件刪除

//iterator erase(iterator first, iterator last);

//刪除乙個範圍

//size_type erase(const key& key);

//通過關鍵字刪除

a.erase(2

); getchar();

return0;

}

vector操作

//

用陣列初始化容器

int a = ;

vector

nums(begin(a), end(a));

字串和數字相互轉換, char*和string相互轉換。 參考鏈結

char c[123] = "

35245324523";

int num = 1234

; sprintf_s(c, "%d

", num);//

數字轉字串

sscanf_s(c, "

%d", &num);//

字串轉數字,注意是&num,不是num

string s(c); //

char*轉string

const

char *p = s.c_str();//

string轉const char*

reverse(s.begin(), s.end());//

reverse反轉

cout << s << "\n"

<< c;

fstream,stringstream,iostream三種輸入輸出流 

int main(void

)

查詢子串

string s = "

123asdf";

if (s.find("

3as") == string

::npos)

cout

<< "

not find";

else

cout

<< "

find

";

set操作, set元素唯

一、自動排序,不支援下標操作,只能用迭代器 

stl中的set容器的一點總結    

//

插入set

a;a.insert(5);

cout

<< a.size() << endl; //

1 a.insert(5

); cout

<< a.size() << endl; //

1 a.insert(2

); cout

<< a.size() << endl; //

2 a.insert(9

); cout

<< a.size() << endl; //

3

//遍歷

//注意1: set不支援下標操作,只能用迭代器

//注意2: set容器是排好序的

for (set

::iterator it = a.begin(); it != a.end(); it++)

cout

<< *it << endl;//

2 5 9

//查詢

if (a.find(2) !=a.end())

cout

<< "

find

"

a.erase(2

); cout

<< a.size() << endl;

1

刷題小知識點

二維陣列的指標寫法 include using namespace std int main for int i 0 i 3 i cout a 1 2 endl system pause return 0 char a 10 則最後乙個必須是 0 前面9個數 char a 多維陣列最後一維必須有值。...

python leetcode刷題知識點筆記2

第一種方法 bfs廣度優先搜尋,使用雙端佇列deque 因為效能比另外兩種queue好得多 在大迴圈內對二叉樹的每個層做一次遍歷,range len queue 使只遍歷當前的層,每次大迴圈ans加1。由於每個節點僅訪問一次,所以時間複雜度o n import collections class s...

刷題知識點總結(C )

string中尋找子串 替換字串 string字串判斷是否被訪問過 部分揹包問題通式 區間貪心 哈夫曼樹 將char字元變成int 向下取整和向上取整 當使用二維陣列超時的時候,可以使用二維map lower bound 和upper bound set iterator tp 遇到有關圖的題時,鄰...