STL常用工具集
string
count(也可用在數組,Vector等中)用來數元素個數
#include <bits/stdc++.h> using namespace std; int main(){string s = "1.32.31.89";int cnt = count(s.begin(),s.end(),'.'); //左閉右開 cout<<cnt<<endl; //3int a[] = {10,20,30,30,20,10,10,20}; //8個元素 cnt = count(a, a+8, 10);cout<<"10 appears"<<" "<<cnt<<endl; //3vector<int>ve(a,a+8); //數組轉vectorcnt = count(ve.begin(), ve.end(), 20); cout<<"20 appears"<<" "<<cnt<<endl; //3return 0; }to_string
stoi,stof,sotd
reverse
find(string::npos)(字符串)
substr
insert(將字符串插入到輸入位置的前面)
string流
//將一行中的空格吞掉 無論連續幾個空格int cnt=0;stringstream ss(s);while(ss>>s) ans[cnt++]=s;判斷類(isalnum)
轉換類(tolower,toupper)
vector
reverse
clear
沒有find,只有find函數(數組也是)
vector<int>ve;ve.push_back(2); ve.push_back(3);int t = find(ve.begin(),ve.end(),3)-ve.begin();cout << t; //1set
insert
find
end
erase(元素值)
upper_bound(配合*得到元素值)
rbegin(配合*得到元素值)
if(t<*s.rbegin()){ //如果找得到隊伍 s.erase(*(s.upper_bound(t)));}stack
top(使用時要同時判斷size)
pop(同上)
總結
- 上一篇: PAT乙级题目答案汇总PAT (Basi
- 下一篇: Codeforces Round #71