随笔分类 -  C++

1
摘要:dijkstra版 for(int v = 0; v < n; v++) { if(visit[v] == false && e[u][v] != inf) { if(dis[u] + e[u][v] < dis[v]) { dis[v] = dis[u] + e[u][v]; w[v] = w[u 阅读全文
posted @ 2022-02-09 00:24 XA科研 阅读(26) 评论(0) 推荐(0) 编辑
摘要:整型转字符串: int c=100; string s=to_string(c); cout<<s<<endl; 字符串转整型: string s="10000"; int c=atoi(s.c_str()); cout<<c<<endl; 阅读全文
posted @ 2022-02-02 00:07 XA科研 阅读(15) 评论(0) 推荐(0) 编辑
摘要:字符串反转: string s; reverse(s.begin(),s.end()); 单个数字转字符: string s=""; int n=9; s+=(n+'0'); cout<<s<<endl; 单个字符转数字: char c='9'; int n=c-'0'; cout<<c<<endl 阅读全文
posted @ 2021-07-11 23:15 XA科研 阅读(161) 评论(0) 推荐(1) 编辑
摘要:getline用来读入带空格的字符串 使用方式 getline(cin,st); 注意点: 若scanf或cin与getline一起使用,需要清空scanf或cin的缓冲内容 scanf("%d",&n); char c=getchar(); getline(cin,st); 其中c=getchar 阅读全文
posted @ 2021-07-05 23:03 XA科研 阅读(84) 评论(0) 推荐(0) 编辑
摘要:string新技巧: int a, b; cin >> a >> b; string s = to_string(a + b); 阅读全文
posted @ 2021-06-17 23:02 XA科研 阅读(30) 评论(0) 推荐(0) 编辑
摘要:priority_queue又称优先队列,其底层用堆来进行实现。在优先队列中,队首元素一定是当前队列中优先级最高的那一个。 用处:当作最大,最小堆来使用,免去堆的一系列复杂操作。 一、priority_queue的定义 添加头文件#include<queue>,并在头文件下面加上“using nam 阅读全文
posted @ 2021-04-06 23:03 XA科研 阅读(670) 评论(0) 推荐(0) 编辑
摘要:1.cin和cout消耗的时间比scanf和printf多得多,建议用后者 2.memset不能对数组进行任意初始化,只能初始化为-1,0 3.初始化一般用fill 一维数组:fill (array,array+4,5); vector容器:fill (myvector.begin(),myvect 阅读全文
posted @ 2021-02-21 20:54 XA科研 阅读(111) 评论(0) 推荐(0) 编辑
摘要:string 转 char* 使用c_str() #include<bits/stdc++.h> using namespace std; int main(){ string s="abc"; printf("%s\n",s.c_str());//string 转 char * return 0; 阅读全文
posted @ 2021-02-16 23:37 XA科研 阅读(1722) 评论(0) 推荐(0) 编辑
摘要:在return 0前面添加 system("pause"); 可以让程序暂停,防止一闪而过。 阅读全文
posted @ 2021-02-09 22:33 XA科研 阅读(38) 评论(0) 推荐(0) 编辑
摘要:关闭同步,可以提升cin和cout的速度 代码: std::ios::sync_with_stdio(false); 阅读全文
posted @ 2021-02-09 22:06 XA科研 阅读(748) 评论(0) 推荐(1) 编辑
摘要:原因:自定义的****变量与库中重名; 解决:修改一下变量名 阅读全文
posted @ 2021-02-09 00:26 XA科研 阅读(998) 评论(0) 推荐(0) 编辑
摘要:map为映射,可以将任何基本类型(包括STL容器)映射到任何基本类型(包括STL容器) 一、map定义: map<typename1,typename2> mp; 二、访问: map中的键是唯一的 通过下标访问: 例如:mp['c']=20 迭代器访问: map<typename1,typename 阅读全文
posted @ 2021-01-27 14:31 XA科研 阅读(169) 评论(0) 推荐(0) 编辑
摘要:int型变量的取值范围:[-2^31, 2^31 - 1] -> [-2147483648, 2147483647] 0x7fffffff = 2147483647 = (2^31 - 1) = (1 << 31) - 1 0x3fffffff = 1073741823 = (2^30 - 1) = 阅读全文
posted @ 2021-01-27 14:21 XA科研 阅读(11369) 评论(0) 推荐(0) 编辑
摘要:set为集合,是一个内部自动有序且不含重复元素的容器 一、set的定义 set<typename> name; 二、元素访问 set只能通过迭代器(iterator)进行访问 set<typename> ::iterator it; 三、常用函数 (1)insert() insert(x)将x插入s 阅读全文
posted @ 2021-01-27 14:07 XA科研 阅读(145) 评论(0) 推荐(0) 编辑
摘要:pair是一种将两个元素绑在一起的容器,需要使用头文件:#include<utility> 1.定义: pair<typename1,typename2> name; 初始化: pair<string,int>p("hahaha",5); 2.pair元素的访问 示例: #include<iostr 阅读全文
posted @ 2021-01-25 14:53 XA科研 阅读(172) 评论(0) 推荐(0) 编辑
摘要:一、queue queue为队列 定义:queue<typename> name; 常用函数为: (1)push() push(x):将x进行入队 (2)empty() 检测队列是否为空 (3)pop() 令队首元素出队 (4)size() 返回队列元素的个数 (5)front() , back() 阅读全文
posted @ 2021-01-25 14:39 XA科研 阅读(122) 评论(0) 推荐(0) 编辑
摘要:一、max() , min() , abs() max(x,y)和min(x,y)分别返回x和y的最大值和最小值,且参数必须是两个(可以是浮点数) 二、swap() swap(x,y)用来交换x和y的值 三、reverse() reverse(it,it2)可以将数组指针在(t,t2)之间的元素或容 阅读全文
posted @ 2021-01-25 14:16 XA科研 阅读(265) 评论(0) 推荐(0) 编辑
摘要:在C语言中,一般使用字符数组char str[]来存放字符串,但是使用字符数组有时会显得麻烦,C++在STL中加入了string类型,对字符串常用的需求功能进行了封装,使得操作起来更方便,且不易出错。 如果需要使用string ,需要添加string头文件,即#include<string> (注: 阅读全文
posted @ 2021-01-25 11:44 XA科研 阅读(187) 评论(0) 推荐(0) 编辑
摘要:ctrl + shift+a : 代码格式化对齐 ctrl+左右键 : 使光标移动一个单词的距离 shift+左右键 : 可以选中光标左右的一个字符 阅读全文
posted @ 2021-01-24 21:54 XA科研 阅读(647) 评论(0) 推荐(0) 编辑
摘要:一、vector的常见用法详解 1.vector的定义 头文件:#include<vector> 单独定义一个vector: vector<typename> name; 注:如果typename也是一个STL容器,定义的时候要记得在>>符号之间加上空格,因为一些使用C++11之前标准的编译器会把它 阅读全文
posted @ 2021-01-22 21:29 XA科研 阅读(165) 评论(0) 推荐(0) 编辑

1
点击右上角即可分享
微信分享提示