
C++
dotJunz
这个作者很懒,什么都没留下…
展开
-
记录 CLion + QT 环境搭建遇到的问题及解决办法
终于可以运行实例程序了!要改这里原创 2021-03-03 14:42:28 · 320 阅读 · 0 评论 -
bfs超时
力扣 剑指 Offer 13. 机器人的运动范围超时代码原因在于判断一个点多调用了两次fun函数。class Solution {public: struct node { int x, y; }; int dir[2][2] = { {0,1},{1,0}}; int fun(int x) { int ans = 0; while (x != 0) { ans += x % 10;原创 2021-12-17 10:44:21 · 237 阅读 · 0 评论 -
dfs 返回值用bool相对void会快一点
力扣 剑指 Offer 12. 矩阵中的路径超时代码dfs返回值是void,用类内的全局变量flag表示找到或没找到。class Solution {public: bool flag; int vis[210][210]; int dir[4][2] = { {1,0},{0,1},{-1,0},{0,-1} }; int m, n; void dfs(int x, int y, int count, string& word, vector<原创 2021-12-16 21:10:06 · 450 阅读 · 0 评论 -
C++ STL unordered_map和map查找复杂度
unordered_map 查找O(1)map 查找O(logn)原创 2021-12-15 09:24:09 · 4601 阅读 · 0 评论 -
priority_queue自定义比较函数
力扣 973. 最接近原点的 K 个点class Solution {public: struct cmp { bool operator()(pair<vector<int>, int> a,pair<vector<int>, int> b) { return a.second < b.second; } }; vector<vector<int>&g原创 2021-12-14 19:32:34 · 640 阅读 · 0 评论 -
unordered_map和map键的类型问题
unordered_map<vector, int> map1; // 这种用法错误//我们知道c++中有unordered_map和unordered_set这两个数据结构,// 其内部实现是哈希表,这就要求作为键的类型必须是可哈希的,一般来说都是基本类型//所以pair和vector一类的不可以map<vector, int> map2; // 用法正确// map和set内部的实现是树(红黑树,更高级的二叉搜索树),//既然运用到二叉搜索树就必须得有比较两个元素.转载 2021-12-14 19:16:13 · 531 阅读 · 0 评论 -
C/C++中带空格字符串的输入
C语言#include <iostream>using namespace std;int main(){ char str[100]; gets(str); printf("%s\n",str); return 0;}C++ string类型#include <iostream>#include <string>using namespace std;int main() { string str; g原创 2021-09-02 20:51:57 · 914 阅读 · 0 评论 -
C++ int转string
C++ int转stringstring转int原创 2021-02-21 15:59:46 · 143 阅读 · 0 评论 -
C++以空格为分隔符分隔string类型
#include <iostream>#include <sstream>using namespace std;int main(){ string s = "1 2 3"; istringstream str(s); while (str >> s) { cout << s << endl; } return 0;}原创 2021-03-28 11:25:58 · 2098 阅读 · 0 评论 -
C++ 定义常量pi
const double pi = acos(-1);原创 2021-03-27 08:49:17 · 4397 阅读 · 0 评论 -
C++ debug
某一条语句不执行,很可能是我把=写成了==切记!原创 2021-03-20 08:19:49 · 124 阅读 · 0 评论 -
全排列问题 用到递归,散列
全排列问题用到递归,散列#include <iostream>using namespace std;const int maxn = 100;int n, p[maxn], hashTable[maxn] = {false};void generate(int index) { if (index == n + 1) { for (int i = 1; i <= n; i++) { cout << p[i] << " "; }原创 2021-03-18 22:16:31 · 84 阅读 · 0 评论 -
C++ 万能头文件
#include<bits/stdc++.h>原创 2021-03-14 09:36:41 · 4359 阅读 · 3 评论 -
C++ int,long long范围
C语言中int的取值范围为:-2147483648 ~ 2147483647 10位数-2^31 ~ 2^31 - 1当数据可能大于10^9时,用long long原创 2021-03-13 20:56:44 · 7090 阅读 · 0 评论 -
C++ 连接mysql
一开始提示无法打开头文件#include<mysql.h>libmysql.lib原创 2021-03-12 16:46:53 · 306 阅读 · 0 评论 -
C++ 命名规范和快捷键
命名规范类名首字母大写,单词和单词之间首字母大写函数名变量名称首字母小写,单词和单词之间首字母大写.快捷键注释ctrl + /运行ctrl + r编译ctrl + b字体缩放 ctrl +鼠标滚轮查找ctrl + f整行移动ctrl + shift + ↑或者↓帮助文档 F1自动对齐ctrl + i;同名之间的.h 和.cpp切换 F4...原创 2021-03-09 17:18:43 · 251 阅读 · 0 评论 -
C++ 注释代码快捷键
选中要注释的代码ctrl + /完成原创 2021-03-09 16:52:39 · 5365 阅读 · 1 评论 -
闰年
能被4整除且不能被100整除 或 能被400整除bool isLeap(int y){ return (y%400==0)||(y%4==0 && y%100!=0);}原创 2021-03-09 09:12:08 · 112 阅读 · 0 评论 -
C++ 字符串和整数互转 代码实现
代码#include <iostream>#include <sstream>//用到stringstreamusing namespace std;//stirng转intvoid s2i(string &str, int &num){ stringstream ss; ss << str; ss >> num;}//int转stringvoid i2s(int &num, string &原创 2021-03-08 16:00:28 · 143 阅读 · 0 评论 -
getline() 和 cin.getline() 的区别
#include <iostream>#include <string>using namespace std;int main(){ char a[100]; cin.getline(a, 100); printf("%s", a); return 0;}cin.getline() 第一个参数是字符数组,第二个参数是个数#include <iostream>#include <string>usin原创 2021-03-06 22:33:11 · 176 阅读 · 0 评论 -
cin.getline(b,100); 之前有输入记得getchar();
读入一行数据之前,如果有输入,要getchar();错误代码#include <iostream>#include <string>using namespace std;const int MAX = 100000;char b[MAX];int main(){ int n; cin >> n; //getchar(); int a[MAX]; int k = 0; for(int i = 0; i原创 2021-03-06 22:16:05 · 164 阅读 · 0 评论 -
VS2019 getline()
string str;getline(cin, str)char str[100];cin.getline(str, 100);原创 2021-02-25 00:34:10 · 713 阅读 · 0 评论 -
C++ VS2019 用cin.getline(str,100);代替gets(str);
#include <iostream>#include <string>#include <cstring>#include <cstdio>#include <stdio.h>using namespace std;int main() { char words[100][100]; char str[100]; cin.getline(str,100); int len = strlen(str); int r = 0,原创 2021-02-23 16:23:54 · 688 阅读 · 0 评论