@TaoSama
2017-01-17T20:17:18.000000Z
字数 1826
阅读 1422
1: Implementation with STL
Learning-ACM
C-functions
- cctype
- isalnum, isalpha, isdigit, islower, isupper //bool
- tolower, toupper //char lowerC = tolower(c);
- cmath
- 三角函数系列,pow, log, etc. // log(x) = , log10(x) =
- 浮点数!! // int x = pow(10, 2) = 99.9999999 = 99
- cstdio
- getchar, putchar, gets, puts 非格式化的 %c
//10 15
scanf("%d%d", &x, &y);
char c[2];
scanf("%s", c);
c[0], *c, if(*c == 'Q')
- scanf, printf 格式化的
- stdin, stdout
- sprintf(char* dest, "%2d:%2d", 12, 00) => dest: "12:00"
- 数字与字符串互转
- atoi // char digit[10] = "10"; int x = atoi(digit);
- sprintf
- cstring
- strlen(const char* src)
- strcpy(char* dest, const char* src)
- strchr(const char*, char c) = char*
char src[10] = "abcde", char c = 'c';
char* pos = strch(src, c);
int posInt = pos - src; // 2
- strstr(const char* src, const char* pattern) = char*
- strcmp(const char* lhs, const char* rhs)
- first different char, lhs - rhs, negative, 0, positive
- climits
- 各种类型的最大最小值,平常自己感觉一下就好了
- char -256 ~ 255 1byte // CHAR_MAX, CHAR_MIN
- short -3e4 ~ 3e4 2bytes //
- int -2e9 ~ 2e9 4bytes
- long long -9e18 ~ 9e18 8bytes
- float 3e-38 ~ 3e38 精度6~7位 4bytes
- double 1e-308 ~ 1e308 精度15~16位 8bytes
- long double windows至少10bytes, linux 16bytes 精度自己感受一下
C++ algorithm
- sort
sort(begin, end, cmp);
- find
find(begin, end, x) = iterator //O(n)
- fill
- replace(ForwardIterator first, ForwardIterator last, const T& old_value, const T& new_value)
- reverse
- unique //sorted list
- lower_bound, upper_bound //sorted list
- random_shuffle
- merge
- min, max, min_element, max_element
- next_premutation
C++ others
- complex
- functional
- initializer_list (C++11)
- tuple (C++11)
C++ containers
Type
- list, forward_list
- map, set
- queue, stack, deque, priority_queue
- vector
- bitset
- array (c++11)
- unordered_map, unorder_set (c++11)
Usage
C++ string
- string(const char*), string(n, char)
- insert(positon/iterator, char/string)
- erase(position, len), erase(iterator), erase(begin, end)
- substr(position, len), find(char/string, [position])
- c_str
- string::npos
- operator+
- getline
- stoi,...., to_string (C++ 11)
Suggestions
除非必要,尽量不要手写已有的STL algorithms
不卡时间的情况,尽量使用STL Containters