
c++stl
文章平均质量分 65
哎呀呀呀呀呀呀
这个作者很懒,什么都没留下…
展开
-
vector利用swap()函数进行内存的释放,防止爆内存
vector利用swap()函数进行内存的释放首先,vector与deque不同,其内存占用空间只会增长,不会减小。比如你首先分配了10,000个字节,然后erase掉后面9,999个,则虽然有效元素只有一个,但是内存占用仍为10,000个。所有空间在vector析构时回收。empty()是用来检测容器是否为空的,clear()可以清空所有元素。但是即使clear(),所占用的内存空间......转载 2020-03-16 01:07:58 · 900 阅读 · 0 评论 -
关于java的输出
如果想控制位数要用System.out.printf("%.1f",m);原创 2018-09-15 20:18:58 · 131 阅读 · 0 评论 -
String字符串与字符(char类型)数组互相转换
java主要是两个方法:1.String类的toCharArray()方法,将字符串转为字符(char)数组String ss=”abc”;char[] cc;cc=ss.toCharArray();这时cc={‘a’,’b’,’c’};2.String类的valueOf()方法,将字符(char)数组转换为字符串char[] cc={‘a’,’b’,’c’};s...转载 2018-08-03 15:01:17 · 22555 阅读 · 0 评论 -
数字与字符串之间的转换
2、数字转字符串:使用sprintf()函数char str[10];int a=1234321;sprintf(str,"%d",a);--------------------char str[10];double a=123.321;sprintf(str,"%.3lf",a);--------------------char str[10];int a=175;spri...转载 2018-08-03 14:55:14 · 480 阅读 · 0 评论 -
优先队列的用法
主要有三种1.priority_queue <int> i;priority_queue <double> d;自动由大到小排序2.struct node{ int x,y;bool operator < (const node & a) const{ return x<a.x; } //若需要有小到大排序就把这一行的<...原创 2018-08-03 12:41:27 · 510 阅读 · 0 评论 -
set中要注意的问题
#include<stdio.h>#include<set>#include<iostream>using namespace std;set<int>a;set<int>::iterator it,it1;int main(){ int n; cin >> n; while (n--) { int ...原创 2018-07-15 17:48:41 · 307 阅读 · 0 评论 -
可打印字符
ascII码33--127,用isgraph(char )来判断原创 2018-07-15 17:31:46 · 1732 阅读 · 0 评论 -
容器注意有的不能对迭代器进行加减法
能进行算术运算的迭代器只有随即访问迭代器,要求容器元素存储在连续内存空间里,vector,string,deque的迭代器是有加减法的,但是map,set,multimap,multiset的迭代器是没有加减法的,list也不可以 该知识点是在刷leetcode347题时想到的...原创 2018-07-15 16:23:14 · 2372 阅读 · 1 评论 -
strtok函数,使一个认定字符变为这个串的分隔符
用固定字符做字符串分隔符#include <iostream>#include <algorithm>#include <stdio.h>#include <stdlib.h>#include <string.h>using namespace std;const int N = 1000;char s[N...原创 2018-07-16 18:02:58 · 224 阅读 · 0 评论 -
奇奇怪怪的题目 求最长递增子序列,map黑科技
F. Consecutive Subsequencetime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given an integer array of length nn.You have to choose some subs...原创 2018-07-10 16:01:07 · 206 阅读 · 0 评论 -
vector邻接表的建立(用vector的目的是因为不能确定每个点有几条边)
一。用结构体#include<stdio.h> #include<vector> #include<algorithm> #include<iostream>#include<algorithm>using namespace std; struct Edge{ int to; int cos...转载 2018-05-26 11:48:04 · 371 阅读 · 0 评论 -
迭代器
迭代器实际上是对“遍历容器”这一操作进行了封装。在编程中我们往往会用到各种各样的容器,但由于这些容器的底层实现各不相同,所以对他们进行遍历的方法也是不同的。例如,数组使用指针算数就可以遍历,但链表就要在不同节点直接进行跳转。这是非常不利于代码重用的。例如你有一个简单的查找容器中最小值的函数findMin,如果没有迭代器,那么你就必须定义适用于数组版本的findMin和适用于链表版本的findMin...转载 2018-05-26 11:12:36 · 1555 阅读 · 0 评论