acm的STL容器之杂乱篇

2018-07-13

1.利用memset(数组名称,0/1,sizeof(数组))

在比赛中,遇到动态数组问题一般不用申请动态数组(为了兼容c)。

比如用深、广搜的时候储存邻接矩阵,利用memset,

第二个参数填0代表清理,

填1代表用-1充填(因为以补码的形式储存)

2.大量增删用list而不用vector

3.使用getline(cin,line)来读取一行,然后用stringstream将句子中的内容单独给string

 1 #include<iostream>
 2 #include<string>
 3 #include<sstream>
 4 //在输入的只有小写字母和空格的句子中,首字母大写。
 5 using namespace std;
 6 int main(){
 7     string line, a;
 8     while(getline(cin, line)){
 9         stringstream ss(line);
10         int first = 0;
11         while(ss >> a){
12             if(!first) first = 1;
13             else cout << " ";
14             if(a[0]>='a'&&a[0]<='z'){
15                 a[0]-=32;
16             }
17             cout << a;
18         }
19         cout << endl;
20     }
21     return 0;
22 }

4.队列有queue,也有dequeue(双增队列)

5.利用itoa(int val, char*, int ind)函数转化任意进制,strtor(char *,char *, int ind)

(待完善)

原文地址:https://www.cnblogs.com/VsKendo/p/9303214.html