C++学习
永兴呵呵哒
谁知道明天和意外,哪一个先来呢
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
sort排序函数
参考文章:https://blog.youkuaiyun.com/w_linux/article/details/76222112原创 2019-03-10 20:16:42 · 294 阅读 · 0 评论 -
C++笔试输入输出
1、输入数据包括多组。 每组数据一行,每行的第一个整数为整数的个数n(1 <= n <= 100), n为0的时候结束输入。 接下来n个正整数,即需要求和的每个正整数。 #include<iostream> using namespace std; int main() { int n; while (cin >> n) { if (n == 0) br...原创 2019-08-27 14:45:21 · 3557 阅读 · 0 评论 -
LeetCode对链表的一些操作题目
//判断是否是环形链表(141) class Solution { public: bool hasCycle(ListNode *head) { ListNode *fast = head, *slow = head; while(fast && fast->next){ slow = slow->nex...原创 2019-07-24 19:34:29 · 183 阅读 · 0 评论 -
使用vector创建二维数组以及添加元素
int main() { vector<vector<int>> dp(5, vector<int>(10,3)); //创建5*10二维数组 dp.push_back(vector<int>(10,5)); //添加一行,成为了6*10数组 dp[4][3] = 100; ...原创 2019-07-19 17:12:28 · 7667 阅读 · 0 评论 -
LeetCode刷题分类
以下代码都来自该博客: 博客链接:https://www.cnblogs.com/grandyang/p/4606334.html 一、回文串相关 //验证是否为回文字符串(125) class Solution { public: bool isPalindrome(string s) { int left = 0, right = s.size() - 1 ; ...原创 2019-07-23 22:52:33 · 641 阅读 · 0 评论 -
C++实现栈与C++实现队列
参考博客:https://blog.youkuaiyun.com/zhy_cheng/article/details/8090346 使用标准库的栈和队列时,先包含相关的头文件 #include<stack> #include<queue> 栈和队列的定义如下: stack<int> stk; queue<int> q; queue<TreeNode*...原创 2019-07-16 17:23:16 · 595 阅读 · 0 评论 -
C++实现马拉车算法(用于求最大回文子串)
参考文章:https://blog.youkuaiyun.com/dyx404514/article/details/42061017 参考文章:https://www.cnblogs.com/grandyang/p/4475985.html #include <vector> #include <iostream> #include <string> using na...原创 2019-07-23 16:19:26 · 566 阅读 · 2 评论 -
C++实现二叉树中序遍历以及栈的使用
递归实现 //二叉树的定义 struct TreeNode { int val; TreeNode *left; TreeNode *right; TreeNode(int x) : val(x), left(NULL), right(NULL) {} }; class Solution { public: vector<int>...原创 2019-07-16 14:57:13 · 1718 阅读 · 0 评论 -
C++实现快速排序
#include<iostream> #include<vector> using namespace std; void quicksort(vector<int> &nums ,int left, int right) { if (left > right) { return; } int i = left, j = right, ...原创 2019-07-13 14:25:20 · 202 阅读 · 0 评论 -
C++ 实现冒泡排序与vector初始化方法
C++ 实现冒泡排序 #include<iostream> #include<vector> using namespace std; void bubblesort(vector<int> &nums) { int i = 0, j = 0 , temp = 0; for (int i = 0; i < nums.size(); i++) ...原创 2019-07-13 11:46:12 · 1339 阅读 · 0 评论 -
c++中unordered_map和map的不同以及他们的遍历
参考文章:https://blog.youkuaiyun.com/BillCYJ/article/details/78985895原创 2019-05-15 12:01:51 · 19106 阅读 · 2 评论 -
C++取近似值
针对问题:将浮点数取整或者四舍五入 注意函数取整返回值均为double型,在用printf输出时应注意 使用函数实现需要添加一个头文件 #include<iostream> #include<cmath> using namespace std; int main() { double m=3.5; cout<<ceil(m)<<en...原创 2019-05-15 11:39:36 · 2476 阅读 · 0 评论 -
求比n小的一个数,使其各位数的乘积最大
#include<iostream> #include<algorithm> using namespace std; int solve(int n) { if (n == 0) return 1; else if (n < 10) return n; else return max(solve(n / 10) * (n % 10), solve(n / 1...原创 2019-09-23 20:50:42 · 582 阅读 · 1 评论
分享