- 博客(144)
- 资源 (15)
- 问答 (4)
- 收藏
- 关注
原创 快速排序(quicksort)算法-C++实现
#include <iostream>#include <vector>using namespace std;int partition(vector<int> &arr, int low, int high) { int pivot = arr[low]; int i = low + 1, j = high; while (true) { while (i < high && arr[i.
2021-08-31 11:34:40 479
原创 C++逐行读取文本文件(模板)
#include <vector>#include <iostream>#include <string>#include <fstream>using namespace std;int main() { ifstream infile; infile.open("/home/jcglqmoyx/projects/cpp-projects/test/P1.cpp", ios::in); if (!infile.is_o.
2021-08-31 11:33:56 570
原创 三路快排-C++实现
#include <vector>#include <iostream>using namespace std;void quicksort(vector<int> &arr, int low, int high) { if (low >= high) return; int pivot = arr[low]; int i = low + 1, lt = low, gt = high; while (i <=.
2021-08-31 11:33:28 349
原创 最大公约数(GCD)算法与最小公倍数(LCM)算法-C++实现
int gcd(int m, int n) { return m % n == 0 ? n : gcd(n, m % n);}int lcm(int a, int b) { return a * b / gcd(a, b);}
2021-08-31 11:32:50 300
原创 堆排序-C++实现
#include <vector>#include <iostream>using namespace std;void sink(vector<int> &arr, int i, int &end) { int t = i; if (i * 2 + 1 <= end && arr[i * 2 + 1] > arr[t]) t = i * 2 + 1; if (i * 2 + 2 <= .
2021-08-31 11:32:11 159
原创 在Ubuntu上为软件安装桌面快捷方式
本文以在Ubuntu上为Sublime Text 3创建桌面快捷方式为例。进入/usr/share/applications目录,新建sublime_text.desktop(需要使用管理员身份新建)。cd /usr/share/applicationssudo gedit sublime_text.desktop在sublime_text.desktop中添加如下内容:[Desktop Entry]Version=1.0Type=ApplicationName=Sublime Te
2021-08-31 11:31:18 305
转载 常见英文咒语与低俗词汇一览表(应避免使用)
最近实现一种英文词汇过滤机制,但是找不到应避免使用的词汇列表,于是在Bing上搜索了一下,得到以下结果,仅供开发人员参考。转自:List of Swear Words, Bad Words, & Curse Wordsanusarsearseholeassass-hatass-jabberass-pirateassbagassbanditassbangerassbiteassclownasscockasscrackerassesassfaceassfucka
2021-08-31 11:30:26 10830
原创 我的Ubuntu装机配置
新装机要安装的软件:可以用命令行安装的软件或者软件包sudo apt install openjdk-8-jdk openjdk-11-jdk openjdk-11-source golang nodejs npm python3-pip php clang-12 clang mysql-client mysql-server nginx tomcat9* vim vim-gtk vim-youcompletemegit maven cmake make ffmpeg autoconf libglu
2021-08-31 11:29:00 270
原创 C++使用sscanf方便地读取数据
力扣class Solution {public: int get(string s) { int h, m; sscanf(s.c_str(), "%d:%d", &h, &m); return h * 60 + m; } int numberOfRounds(string startTime, string finishTime) { int x = get(startTime), y =
2021-08-31 11:26:32 393
原创 Ubuntu 20.04设置开机自启动
Ubuntu 20.04的服务管理是基于systemd的,因此设置服务自启动最推荐的方法是创建一个systemd服务文件,配置好要执行的服务。过程如下:创建我们需要开机自启动的脚本,例如test.sh,其内容如下:#!/bin/bashcd ~/touch 11111111111.txt注意,开头一定要加上:#!/bin/bash2. 在/etc/systemd/user目录下创建一个systemd服务文件, 命名为user-defined.service, 内容如下:[U
2021-08-31 11:25:36 2534 4
原创 希尔排序 代码
这个排序方法看起来简单,实现起来还是很麻烦的。写法一 public static void sort(int[] arr) { int n = arr.length; for (int gap = n / 2; gap > 0; gap /= 2) { for (int i = gap; i < n; i++) { for (int j = i; j >= gap; j -= gap)
2020-12-02 12:40:28 347
原创 解决JetBrains系列Git push失败问题
最近在使用JetBrains系列IDE执行Git push操作时,经常遇到push失败问题,报错信息如下:Push failedInvocation failed Server returned invalid Response. java.lang.RuntimeException: Invocation failed Server returned invalid Response. a...
2020-04-26 10:50:41 1209
原创 LeetCode-136. Single Number
Given anon-emptyarray of integers, every element appearstwiceexcept for one. Find that single one.Note:Your algorithm should have a linear runtime complexity. Could you implement it without us...
2020-04-01 16:43:06 257
原创 Java判断回文字符串
public class Palindrome { public static boolean isPalindrome(String s) { int len = s.length(); for (int i = 0; i < len / 2; i++) if (s.charAt(i) != s.charAt(len - i...
2020-03-30 12:01:15 358
转载 The result of division and remainder for negative integers in Java
In Java programming, th quotient a / brounds toward 0; the remainder a % b is defined such that (a / b) * b + a % b is always equal to a. For example, -14 / 3 and 14 / -3 are both -4, but -14 % 3 is...
2020-03-27 22:46:59 217
原创 Binary Search in Java
Recursive version:int recursiveBinarySearch(int[] arr, int key, int low, int high) { if (low > high) return -1; int mid = low + (high - low) / 2; if (arr[mid] == key) ret...
2020-03-20 19:56:43 208
原创 Evaluating the square root of a number
double sqrt(double n) { if (n < 0) return Double.NaN; double err = 1e-15, t = n; while (Math.abs(t - n / t) > t * err) { t = (t + n / t) / 2; } ...
2020-03-20 17:56:23 252
原创 Greatest Common Divisor
int gcd(int p, int q) { if (p % q == 0) return q; int r = p % q; return gcd(q, r);}
2020-03-20 01:20:26 253
转载 LeetCode-1114. Print in Order
Description:Suppose we have a class:public class Foo { public void first() { print("first"); } public void second() { print("second"); } public void third() { print("third"); }}The same...
2020-03-18 21:23:29 247
转载 LeetCode-206. Reverse Linked List
Reverse a singly linked list.Example:Input: 1->2->3->4->5->NULLOutput: 5->4->3->2->1->NULLSolution:/** * Definition for singly-linked list. * public class ...
2020-03-18 14:24:05 220
原创 Java concurrency demo
import java.util.Arrays;import java.util.concurrent.locks.Condition;import java.util.concurrent.locks.Lock;import java.util.concurrent.locks.ReentrantLock;public class Bank { private final d...
2020-03-17 21:38:39 217
原创 【Java】粗略统计txt文本中单词的个数
import java.util.HashSet;import java.util.Scanner;import java.util.Set;public class ReadText { public static void main(String[] args) { Set<String> words = new HashSet<>()...
2020-03-10 22:40:46 650
转载 LeetCode 696. Count Binary Substrings
Description:Give a strings, count the number of non-empty (contiguous) substrings that have the same number of 0's and 1's, and all the 0's and all the 1's in these substrings are grouped consecutiv...
2020-03-08 16:56:27 225
原创 Ubuntu 安装搜狗拼音输入法
1. 下载搜狗拼音Linux版。2. 打开终端,执行sudo apt updatesudo apt upgradesudo apt-get install -f3. 进入到输入法安装包所在目录,执行sudo dpkg -i sogoupinyin_2.3.1.0112_amd64.deb(即安装包名)如果报出error,试一下sudo apt --fix-brok...
2020-02-04 10:26:13 340
转载 常用位运算操作
1. 判断一个整数是否为偶数(Java)boolean isEven (int n) { return (n & 1) == 0;}// 下面的代码用来判断一个整数是否为奇数boolean isOdd (int n) { return (n & 1) == 1;}应用:统计一个int型数组中偶数的和:int sumOfEvenValues(...
2020-01-01 22:40:58 355
原创 判断平年和闰年
判断平年(common year)和闰年(leap year)的计算方法很简答:1. 如果年份是整百年份,用年份除以400,没有余数即为闰年,有余数即为平年。2. 如果年份不是整百年份,用年份除以4,没有余数即为闰年,有余数即为平年。说明:2096年和2104年都是闰年,但2100年是平年。所以“四年一润”的说法是不对的,正确说法应该是:“四年一闰,百年不闰,四百年再闰”。判断某一...
2019-12-29 18:59:58 14821
原创 (Java) 求一个数组中最大的三个数 和 最小的两个数
public int maximumProduct(int[] nums) { if (nums.length < 3) return 0; // 开始 int min1 = Integer.MAX_VALUE; int min2 = Integer.MAX_VALUE; int ...
2019-12-24 19:31:25 822
原创 Swap Salary-LeetCode_No.627
Description :Given a tablesalary, such as the one below, that has m=male and f=female values. Swap all f and m values (i.e., change all f values to m and vice versa) with asingle update statement...
2019-11-28 11:31:21 208
原创 Nth Highest Salary-LeetCode_No.177
Write a SQL query to get thenth highest salary from theEmployeetable.+----+--------+| Id | Salary |+----+--------+| 1 | 100 || 2 | 200 || 3 | 300 |+----+--------+For example...
2019-11-28 00:57:49 208
原创 Duplicate Emails-LeetCode_No.182
Description: Write a SQL query to find all duplicate emails in a table namePerson.+----+---------+| Id | Email |+----+---------+| 1 | [email protected] || 2 | [email protected] || 3 | [email protected] |+----+------...
2019-11-28 00:14:10 201
原创 Determine whether an integer is a palindrome using Java
class Solution { public boolean isPalindrome(int x) { if (x < 0 || (x % 10 == 0 && x != 0)) { return false; } int revertedNumber = 0; while...
2019-11-23 03:17:39 256
原创 Calculating the n-th Number of Fibonacci Sequence Using Java
import java.math.BigInteger;public class Test { public static void main(String[] args) { System.out.println(f(BigInteger.valueOf(5))); System.out.println(f(BigInteger.valueOf(6)...
2019-11-20 13:08:06 263
原创 Using MySQL keyword as a field name yields an exception
2019-11-12 22:01:42 DEBUG [http-nio-8080-exec-5] org.springframework.jdbc.support.SQLErrorCodeSQLExceptionTranslator - Translating SQLException with SQL state '42000', error code '1064', message [Yo...
2019-11-12 22:12:00 244
转载 SpringMVC freemarker 中 Could not resolve view with name 'XXX.ftl' in servlet with name 'SpringMVC'
原因为freemarker本身配置了templateLoaderPath而在viewResolver中不需要配置prefix,且路径前缀必须配置在templateLoaderPath中。路径配置错误导致以上错误信息。
2019-10-22 23:50:45 466
原创 配置FreeMarker时IDEA提示cannot resolve property 'templateLoaderPath'
原因: 缺少spring-context-support.jar依赖。
2019-10-21 23:46:55 2316
原创 MySQL在指定字段后添加一个新字段
ALTER TABLE jc_wechat_user_tag ADD tagid VARCHAR(5) NOT NULL COMMENT "标签所对应的tagid, 创建用户标签后, 由微信公众平台返回" AFTER wechat_id;
2019-10-09 11:37:10 2518
原创 META-INF/MANIFEST.MF file not found in unnamed.war
AddMANIFEST.MFtoYOUR_PROJECT_NAME/web/src/main/webapp/META-INF/folder with the simple content:Manifest-Version: 1.0Or you can generate it usingIntelliJ Artifacts Configuring
2019-09-30 10:02:53 2010
原创 Java获取音频播放时长
1. 获取.amr音频文件播放时长import java.io.File;import java.io.IOException;import java.io.RandomAccessFile; public class AmrFileTimeLengthSample { public static long getAmrDuration(File file) throws IOEx...
2019-09-23 15:56:47 1660
原创 JS实现阿拉伯数字转韩文
function convertHangul(number) { var han1 = ["영", "일", "이", "삼", "사", "오", "육", "칠", "팔", "구"]; var han2 = ["", "십", "백", "천"]; var han3 = ["", "만", "억", "조", "경"]; var result = "";...
2019-09-23 00:45:26 333
原创 微信公众号开发-素材管理-调用接口返回结果一览表
上传永久素材返回结果 图片 视频 音频 缩略图 media_id media_id media_id media_id url url 获取单个素材返回结果 图片 视频 音频 缩略图 图片 title 音频 (无此类型,必...
2019-09-21 18:31:44 631
微信公众号接口调用次数清零需要的jar文件
2019-09-20
喵喵咪鼠标自动点击器1.0(Win 64位)
2018-10-17
Java应用定制工厂
2018-10-11
公众号开发删除用户标签
2019-10-17
公众号获取用户列表openid问题
2019-10-16
jdbc连接MySQL报错, 有没有大神帮忙解决一下
2018-12-08
JSTL中使用<c:set>标签中文会有乱码
2018-12-03
TA创建的收藏夹 TA关注的收藏夹
TA关注的人