随笔分类 -  C/CPP学习

1 2 3 4 5 ··· 10 下一页
摘要:typedef vector Container; void printVec(const Container& data) { for(int i : data) printf("%d ", i); printf("\n"); } void checkSort(function sortFunc) { printVec(sortFunc(Contai... 阅读全文
posted @ 2016-07-13 13:42 wu_overflow 阅读(251) 评论(0) 推荐(0)
摘要:问题是给一个数组,求其最大子数组的和。 思路很简单,只需要记录当前最大和当前的和,若当前的和最大,则替换之,若当前之和小于等于 0,则直接使之为 0,从下一个数开始。考虑到加到最后一个之后无法判断当前和与最大和的大小,所以在最后需要再判断一下。 阅读全文
posted @ 2016-07-03 12:53 wu_overflow 阅读(127) 评论(0) 推荐(0)
摘要:距上一次写博客已是好久了,也是因为自己当时心理比较脆弱,面试的时候面试官跟我说我写的这些东西毛用没有确实当时是给我当头一棒,冷水浇头,然而现在领导给了我一些鼓励,所以我就又来耕耘了。 问题: 给一个升序排序后的数组 nums 和一个整数 N,在数组中添加若干个元素(数) 使得 1~N 内所有的数都可 阅读全文
posted @ 2016-07-03 01:29 wu_overflow 阅读(199) 评论(0) 推荐(0)
摘要:int findMajority(const std::vector<int> &array) { assert(!array.empty ()); int majority = 0; size_t counter = 0; std::for_each(array.cbegin (), array. 阅读全文
posted @ 2016-03-07 22:03 wu_overflow 阅读(212) 评论(0) 推荐(0)
摘要:char* removeMiddleStar(char *str) { if (!str) return str; char *p = str; for(; *p == '*'; ++p); char *q = p; while(*++q != '\0'); while(*--q == '*'); 阅读全文
posted @ 2016-03-03 17:51 wu_overflow 阅读(442) 评论(0) 推荐(0)
摘要:struct Node; using NodePtr = std::unique_ptr<Node>; struct Node { int value; Node* parent = nullptr; NodePtr left = nullptr; NodePtr right = nullptr; 阅读全文
posted @ 2016-03-02 00:57 wu_overflow 阅读(298) 评论(0) 推荐(0)
摘要:一天,他提着酒壶,从家里出来,酒壶中有酒2斗。他边走边唱: 无事街上走,提壶去打酒。 逢店加一倍,遇花喝一斗。 这一路上,他一共遇到店5次,遇到花10次,已知最后一次遇到的是花,他正好把酒喝光了。求可能的方案总数。我的方法: size_t num_solutions = 0; void keepWa 阅读全文
posted @ 2016-02-19 03:15 wu_overflow 阅读(200) 评论(0) 推荐(0)
摘要:bool checkSame(std::string a, std::string b) { constexpr int size = 145; std::vector<int> count(145); std::for_each(a.cbegin (), a.cend (), [&](char c 阅读全文
posted @ 2016-02-15 02:15 wu_overflow 阅读(147) 评论(0) 推荐(0)
摘要:class ThreadRAII { public: // whether join or detach should be called, // when a this object is destroyed. enum class DtorAction { join, detach }; Thr 阅读全文
posted @ 2016-02-14 01:27 wu_overflow 阅读(292) 评论(0) 推荐(0)
摘要:class Node; using NodePtr = std::unique_ptr<Node>; class Node { public: int value; NodePtr next = nullptr; explicit Node(int value_ = 0): value(value_ 阅读全文
posted @ 2016-02-13 15:05 wu_overflow 阅读(626) 评论(0) 推荐(0)
摘要:int convert(char buf[], int value) { constexpr char digits[] = {'9', '8', '7', '6', '5', '4', '3', '2', '1', '0', '1', '2', '3', '4', '5', '6', '7', ' 阅读全文
posted @ 2016-02-11 18:04 wu_overflow 阅读(262) 评论(0) 推荐(0)
摘要:struct Node { int value = 0; Node* next = nullptr; Node(int value_) : value(value_) {} }; Node* createLinkList(const std::vector<int>& data) { if (dat 阅读全文
posted @ 2016-02-11 16:32 wu_overflow 阅读(300) 评论(0) 推荐(0)
摘要:最基本的快排: int partition(int arr[], int l, int r) { int k = l; int pivot = arr[r]; for (int i = l; i != r; ++i){ if (arr[i] < pivot){ std::swap(arr[i], a 阅读全文
posted @ 2016-02-11 01:33 wu_overflow 阅读(269) 评论(0) 推荐(0)
摘要:typedef std::list List;typedef std::map Map;Map getAnagrams(List& input){ Map result; for (const auto& s : input){ auto key = s; ... 阅读全文
posted @ 2016-01-23 02:14 wu_overflow 阅读(167) 评论(0) 推荐(0)
摘要:#include <iostream> #include <vector> #include <string> #include <mysql.h> using namespace std; int main() { ios::sync_with_stdio (false); MYSQL conne 阅读全文
posted @ 2016-01-21 21:24 wu_overflow 阅读(209) 评论(0) 推荐(0)
摘要:void leftRoutate(std::string& s, size_t offset){ auto reverse = [&](size_t begin, size_t end) { --end; while (begin <= end){ ... 阅读全文
posted @ 2016-01-20 03:27 wu_overflow 阅读(185) 评论(0) 推荐(0)
摘要:size_t LCS(const std::string& x, const std::string& y){ if (x.empty () || y.empty ()){ return 0; } const size_t width = x.length () +... 阅读全文
posted @ 2016-01-16 18:12 wu_overflow 阅读(142) 评论(0) 推荐(0)
摘要:vector extractNums(const std::string& s){ vector nums; bool extracting = false; auto begin = s.cbegin(); for (auto it = s.cbegin(); it != ... 阅读全文
posted @ 2015-12-31 14:49 wu_overflow 阅读(189) 评论(0) 推荐(0)
摘要:我之前总是觉得查表最快,然后就老是想着如何制表,睡觉的时候发现我还是太固执了。class NumArray {private: vector* pData_;public: NumArray(vector &nums) { pData_ = &nums; co... 阅读全文
posted @ 2015-12-18 15:47 wu_overflow 阅读(124) 评论(0) 推荐(0)
摘要:题目如下:我的思路是从上往下沉淀。int minimumTotal(vector>& triangle){ for (int i = 1; i != triangle.size(); ++i){ auto& lastRow = triangle[i - 1]; ... 阅读全文
posted @ 2015-12-17 20:02 wu_overflow 阅读(158) 评论(0) 推荐(0)

1 2 3 4 5 ··· 10 下一页