- 博客(23)
- 收藏
- 关注
原创 【leetcode】第四题:寻找两个有序数组的中位数(python3)
题目链接:https://leetcode-cn.com/problems/median-of-two-sorted-arrays/submissions/class Solution: def findMedianSortedArrays(self, nums1: List[int], nums2: List[int]) -> float: i = 0 ...
2020-04-23 23:02:55
283
原创 【leetcode】第三题:无重复字符的最长子串(python3)
题目链接:https://leetcode-cn.com/problems/longest-substring-without-repeating-characters/class Solution: def lengthOfLongestSubstring(self, s: str) -> int: if len(s) == 0: re...
2020-04-22 21:20:24
223
原创 【leetcode】第一题:两数之和(python3)
暴力破解:class Solution: def twoSum(self, nums: List[int], target: int) -> List[int]: delValue = 0 for i in range(len(nums)): delValue = target - nums[i] ...
2020-04-20 22:27:26
632
原创 小算法--将有序数组或有序列表随机排列
import randomrandom.seed()N = 55initList = list(range(1, N))tmp = 0for i in range(len(initList) - 1, 0, -1): tmp = random.randrange(i) initList[i], initList[tmp] = initList[tmp], initLis...
2020-04-17 21:12:49
247
原创 数学--n与7的情愫
求证:8^n % 7 = 1.(n为任意自然数)证明:(1)数学归纳法. n = 1, 8^1 = 8, 8 % 7 = 1,成立 假设n = k时等式成立,即8^k % 7 = 1 => 8^k = 7*P + 1(P为某一自然数) 那么n = k + 1, 8^n = 8^(k+1) = 8*8^k = 8*(7*P +1) = ...
2020-04-17 21:10:59
296
原创 数学--n与6的情愫
求证:(n-1)*n*(n+1)一定能被6整除.(n为不小于2的整数)证明:三个连续的整数至少有一个是偶数,那么乘积能被2整除; 三个连续的整数有且仅有一个能被3整除; 故而(n-1)*n*(n+1)一定能被6整除。...
2020-04-16 23:09:36
383
原创 小算法--括号匹配
#include<iostream>#include<string>#include<vector>using namespace std;int main(int argc,char* argv[]){ string str; vector<char> elem; cin>>str; cha...
2019-09-18 00:06:11
272
原创 关于c++回调函数的一点理解
一直觉得回调函数有点玄乎,今天静下心来好好地聊聊,其实回调函数的本质还是在函数A里调用函数B,那么和常见的调用函数B有什么区别呢?最大的区别在于将想要调用的函数参数化了,那么就可以在不同的场景下调用不同的函数。#include <iostream>typedef int (*pFunc)(int&,int&);int func1(int& x,in...
2019-06-06 21:52:28
335
原创 小算法--按行数复制文件的部分数据到另一文件
#include <iostream>#include <stdio.h>#include <stdlib.h>using namespace std;int main(int argc, char *argv[]){ FILE *fp; //原文件 errno_t err; int lineNum = 0; bool start ...
2019-03-25 18:18:57
247
原创 小算法--任意大于3的整数转化成两个质数和的总对数
#include <iostream>#include <cmath>#define MAX 1000using namespace std;int main(int argc, char *argv[]){ int X; cout << "请输入X的值:"; cin >> X; if (X > MAX || X <...
2019-03-15 15:49:49
316
转载 多线程试炼--读者和作者问题
条件:5个读者,1个作者方法:临界区critical_section、读写锁srwlock#include<iostream>#include <Windows.h>#include <process.h>using namespace std;SRWLOCK srwlockThread;CRITICAL_SECTION csThread_...
2019-03-05 00:35:25
587
转载 vs2013的所有版本密钥
Visual Studio Ultimate 2013:BWG7X-J98B3-W34RT-33B3R-JVYW9Visual Studio Premium 2013:FBJVC-3CMTX-D8DVP-RTQCT-92494Visual Studio Professional 2013:XDM3T-W3T3V-MGJWK-8BFVD-GVPKYTeam Foundation Ser...
2019-03-03 16:34:02
4741
转载 多线程试炼--生产者和消费者问题
条件:1个生产者,2个消费者,5个缓冲区方法:临界区critical_section、信号量semaphore#include <iostream>#include <windows.h>#include <process.h>using namespace std;const int PRODUCT_NUM = 10; //10个产品...
2019-02-15 13:43:16
204
原创 算法排序之堆排序
#include <iostream>using namespace std;void Swap(int &a, int &b){ a ^= b; b ^= a; a ^= b;}void MinHeap(int *a, int i,int n){ int j, temp; j = 2 * i + 1; temp = a[i]; while...
2019-02-14 15:35:19
261
1
原创 算法排序之希尔排序
#include <iostream>using namespace std;void shellSort(int *a, int n){ int gap,i,j,temp; for (gap = n / 2; gap > 0;gap /= 2) { for (i = gap; i < n;i++) { if (a[i]<a[i-gap...
2019-02-14 14:14:27
179
原创 算法排序之归并排序
#include <iostream>using namespace std;void mergeArray(int *a, int first, int mid, int last, int *temp){ int i = first; int j = mid + 1; int m = mid; int n = last; int k = 0; while (i...
2019-02-14 12:27:06
201
原创 小算法--判断给定的数是否为回文数
“回文”是指正读反读都能读通的句子,它是古今中外都有的一种修辞方式和文字游戏,如“我为人人,人人为我”等。在数学中也有这样一类数字有这样的特征,成为回文数(palindromenumber) 。设n是一任意自然数。若将n的各位数字反向排列所得自然数n1与n相等,则称n为一回文数。例如,若n=1234321,则称n为一回文数;但若n=1234567,则n不是回文数。以上信息来自回文数--百度...
2019-02-01 14:33:31
739
原创 socket网络编程之客户端
参考:吴秦(Tyler) 大佬的文章本地配置:vs2013#include <iostream>#include<stdio.h>#include<stdlib.h>#include<string.h>#include<errno.h>#include<sys/types.h>#include<wi...
2019-01-24 18:04:35
257
原创 socket网络编程之服务器端
参考:吴秦(Tyler) 大佬的文章本地配置:vs2013#include<stdio.h>#include<stdlib.h>#include<string.h>#include<errno.h>#include<sys/types.h>#include<winsock2.h>#define MAXLI...
2019-01-22 20:40:24
317
原创 c++中有关String类的构造函数等
String类定义如下:class String{public: String(const char* str = NULL); String(const String &other); ~ String(void); String & operator =(const String &other);private: char *m_data;};...
2018-07-25 11:27:45
263
原创 算法排序之快速排序
#include <iostream>using namespace std;void sort(int *a, int start, int end){ if(start < end) { int key = a[start]; int low = start; int high = end; while(low < high) { ...
2018-06-21 12:16:53
207
原创 对于c++中模板函数的一点体会
何为模板函数,从字面上就可以看出来模板函数必须具备通用性,举个简单却很实用的例子,交换两个值的函数Swap();交换两个字符型void Swap(char &a, char &b)交换两个整型void Swap(int &a, int &b)交换两个浮点型void Swap(float &a, float &b)交换两个布尔型void...
2018-06-10 17:32:52
413
原创 小算法--从一个数组中选择固定个数的元素的所有可能
#include <iostream>using namespace std;#define Select_Num 10void Select(int* arr, int start, int* result, int count, const int Num, const int arr_len){ int i = 0; for(i = start;i<arr_...
2018-06-09 19:29:40
686
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人