Memo_Syntax - RogerRordo/ACM GitHub Wiki

#C++ Syntax ##Containers //注意很多时候iterator表区间首末时为左闭右开区间
###vector iterator begin();
iterator end();
size_type size() const;
reference operator[] (size_type n);
reference front();
reference back();
void push_back (const value_type& val);
void pop_back();
iterator erase (iterator position);
iterator erase (iterator first, iterator last);
void clear();

//sort(v.begin(),v.end());可以实现排序
###queue size_type size() const;
value_type& front();
void push (const value_type& val);
void pop();
###deque size_type size() const;
reference front();
reference back();
void push_front (const value_type& val);
void push_back (const value_type& val);
void pop_front();
void pop_back();
void clear();
###priority_queue template <class T, class Container = vector<T>, class Compare = less<typename Container::value_type> > class priority_queue;
//默认Compare=less,即为大根堆
size_type size() const;
const value_type& top() const;
void push (const value_type& val);
void pop();
###set // /multiset/map/multimap 类似
template < class T, class Compare = less<T>, class Alloc = allocator<T> > class set;
iterator begin();
iterator end();
//end是最后元素的下一个,即空
size_type size() const;
iterator find (const value_type& val) const;
//找不到返回end()
size_type count (const value_type& val) const;
//0/1,除非是 multiset/multimap
iterator lower_bound (const value_type& val) const;
//大于等于val的最小一个
iterator upper_bound (const value_type& val) const;
pair<iterator,bool> insert (const value_type& val);
void erase (iterator position);
size_type erase (const value_type& val);
void erase (iterator first, iterator last);
void clear();
//在 map/multimap里,at()只定义在 C++11*,但operator[]任用* ###unordered_set // 仅C++11! iterator被认为无太大意义而舍去 template < class Key, class Hash = hash<Key>, class Pred = equal_to<Key>, class Alloc = allocator<Key> > class unordered_set;
size_type size() const noexcept;
iterator find ( const key_type& k );
size_type count ( const key_type& k ) const;
//0/1
pair<iterator,bool> insert ( const value_type& val );
size_type erase ( const key_type& k );
void clear() noexcept;
size_type bucket_count() const noexcept;
float load_factor() const noexcept;
float max_load_factor() const noexcept;
void max_load_factor ( float z );
void rehash ( size_type n );

##<cstring>
void * memset ( void * ptr, int value, size_t num );
void * memcpy ( void * destination, const void * source, size_t num );
char * strcat ( char * destination, const char * source );
int memcmp ( const void * ptr1, const void * ptr2, size_t num );
int strcmp ( const char * str1, const char * str2 );
const char * strstr ( const char * str1, const char * str2 );
size_t strlen ( const char * str );

##<string>
//大部分函数对cstring也有类似对string和char的支持,因篇幅限制只描述后者情况;iterator被认为无太大意义而舍去
size_t size() const;
char& operator[] (size_t pos);
// +, =, +=, ==, !=, <, <=, >, >=都对cstring, char, string支持
istream& getline (istream& is, string& str, char delim);
istream& getline (istream& is, string& str);
string& insert (size_t pos, const string& str);
string& insert (size_t pos, const string& str, size_t subpos, size_t sublen);
string& insert (size_t pos, size_t n, char c);
string& replace (size_t pos, size_t len, const string& str);
string& replace (size_t pos, size_t len, const string& str, size_t subpos, size_t sublen);
string& replace (size_t pos, size_t len, size_t n, char c);
string& erase (size_t pos = 0, size_t len = npos);
//改为cstring时subpos为0而不为参数
size_t find (const string& str, size_t pos = 0) const;
size_t find (char c, size_t pos = 0) const;
size_t rfind (const string& str, size_t pos = npos) const;
size_t rfind (char c, size_t pos = npos) const;
//只找pos开始或pos之前开始的
//找不到返回string::npos
string substr (size_t pos = 0, size_t len = npos) const;
const char* c_str() const;
const char* data() const;
//c_str()后有'\0'而data()没有,但data()效率更高

##<algorithm> 待整理 random_shuffle
lower_bound
unique

##<iostream>
###Input istream& get (char& c);
istream& get (char* s, streamsize n);
istream& get (char* s, streamsize n, char delim);
istream& getline (char* s, streamsize n );
istream& getline (char* s, streamsize n, char delim );
//get保留终止符而getline不保留
istream& read (char* s, streamsize n);
istream& ignore (streamsize n = 1, int delim = EOF);
int peek();
istream& putback (char c);
streampos tellg(); //用long long存
istream& seekg (streampos pos);
//t=cin.tellg();...;cin.seekg(t);
//cin.seekg(t);
bool eof() const;
//while (!cin.eof(...))
###Output fmtflags setf (fmtflags fmtfl);
void unsetf (fmtflags mask);
streamsize precision (streamsize prec);
//cout.precision(...); cout<<...;
//此处为精度,若设置fixed,则为小数点后保留位数
//对于以下,e.g. cout<<dec<<...;
//以下三个相对的为其前加no
ios_base& uppercase (ios_base& str);
ios_base& showpos (ios_base& str);
ios_base& showpoint (ios_base& str);
//以下两个的取消,应用cout.unsetf(ios_base::floatfield);
ios_base& scientific (ios_base& str);
ios_base& fixed (ios_base& str);
ios_base& dec (ios_base& str);
ios_base& hex (ios_base& str);
ios_base& oct (ios_base& str);

##Input待整理 ###判断读入完成 while (~scanf())
while (scanf()!=EOF)
while (gets()!=NULL)
while (getchar()!=EOF)

while (cin>>x)
###过滤空格/换行 getchar() 不过滤空格 不过滤换行
scanf("%s") 遇到空格就停

##WARNINGS

  • f(g(1),g(2));先调用g(2)再调用g(1) (特别在read()时注意)
⚠️ **GitHub.com Fallback** ⚠️