今天讲STL 1.pair——<algorithm> 声明形如pair<int,int> x;(不是int也可以),表示x有前后两个成员,都是int类型,调用时写x.first(second); 对pair声明的变量可以不自定义cmp函数,先按照pair中第一个元素优先排序,再按第二个,即第一个元素 ...
分类:
其他好文 时间:
2019-05-03 11:46:43
阅读次数:
134
#include #include #include using namespace std; struct s { string id; int dis; } num[10010]; // 结构体数组变量开的大一点 bool cmp (s a, s b) { // 形参中用结构体定义两个结构体变量... ...
分类:
其他好文 时间:
2019-04-30 01:17:10
阅读次数:
149
// 建一个判断函数,接受两个整形的变量,再通过循环按位判断相等与否,主体函数中调用被调函数,建立一个判断变量。#include using namespace std; bool cmp (int x, int k) { while (k != 0) { int t1 = x % 10; int ... ...
分类:
其他好文 时间:
2019-04-29 20:53:27
阅读次数:
138
#include #include // set 集合中没有重复的元素 using namespace std; int cmp(int t) { int sum = 0; while (t != 0) { sum += t % 10; t /= 10; } return sum; } int ma... ...
分类:
其他好文 时间:
2019-04-29 09:21:09
阅读次数:
177
// 这道题运用的小技巧很多#include #include #include using namespace std; bool cmp (char a, char b) { // 用来递减排序 return a > b; } int main() { string num; cin >> nu... ...
分类:
其他好文 时间:
2019-04-22 20:44:12
阅读次数:
145
一.sorted函数 1.1解释 >>> help(sorted)Help on built-in function sorted in module __builtin__:sorted(...) sorted(iterable, cmp=None, key=None, reverse=False ...
分类:
编程语言 时间:
2019-04-19 13:24:11
阅读次数:
174
#include #include #include #include using namespace std; bool cmp(int a, int b) { return abs(a) > abs(b); } int main() { int n; while (cin >> n && n !... ...
分类:
编程语言 时间:
2019-03-23 22:24:34
阅读次数:
189
1.c++STL中只有list自带了排序函数: (1).若list中存放的是int类型或者string类型,直接利用sort即可: list <int> list1; list1.sort(); 此时默认为升序,若要使用降序,直接自定义cmp函数即可。 (2).若存放的是结构体或其他指针类型,需要自 ...
分类:
编程语言 时间:
2019-03-23 10:26:17
阅读次数:
810
"把数组排成最小的数" 题目描述 输入一个正整数数组,把数组里所有数字拼接起来排成一个数,打印能拼接出的所有数字中最小的一个。例如输入数组{3,32,321},则打印出这三个数字能排成的最小数字为321323。 学习如何把数字转换字符串的函数了 此处cmp函数需要用static关键字, 不知道为什么 ...
分类:
编程语言 时间:
2019-03-11 21:19:13
阅读次数:
269
sort(v.first(),v.end(),cmp())unique(v.first(),v.end(),cmp()) 第三个参数可以传入一个bool型,用来判断是不是相等,返回unique后的超尾max_element(v.first(),v.end(),cmp()) 返回一个迭代器max_el ...
分类:
其他好文 时间:
2019-03-04 21:07:39
阅读次数:
230