
代码实现
辕门骁骑
这个作者很懒,什么都没留下…
展开
-
随机拉丁方阵(Random Latin squares)
大小为n的拉丁方阵是指各行列中的每个符号仅出现一次,随机拉丁方阵生成任意给定n个符号的随机输出。原创 2022-04-30 08:34:13 · 6659 阅读 · 1 评论 -
判断两个三角形是否重合【代码实现】
任务描述给定两个三角形顶点坐标,判断是否有重叠部分。六组三角形坐标如下(0,0),(5,0),(0,5) 和 (0,0),(5,0),(0,6)(0,0),(0,5),(5,0) 和 (0,0),(0,5),(5,0)(0,0),(5,0),(0,5) 和 (-10,0),(-5,0),(-1,6)(0,0),(5,0),(2.5,5) 和 (0,4),(2.5,-1),(5,4)(0,0),(1,1),(0,2) 和 (2,1),(3,0),(3,2)(0,0),(1,1),(0,2) 和原创 2021-06-26 21:23:36 · 3837 阅读 · 0 评论 -
AVL树【代码实现】
C#// Finite Ordered Sets - 4State - Balanced using System;using System.Collections.Generic; public enum Direction { FromLeft, FromRight }; public enum State { Header, LeftHigh, Balanced, RightHigh }; public enum SetOperation{ Union, Inte原创 2020-12-23 17:49:01 · 2969 阅读 · 0 评论 -
优先队列(Priority queue)
优先队列有点类似于队列,但有一个重要的区别:每个元素都以优先级级别添加到优先队列中,进行出队列操作时,具有最高优先级的元素将先出队列。也就是说,元素是按优先级顺序存储在队列中的,而不是按插入顺序存储的。任务:创建一个优先队列,必须至少支持两种操作:入队列。 带有优先级(数字值)的元素添加到队列中。队头出队列。 具有当前最高优先级的元素或元素之一出队并返回它。可以定义其他操作,例如peek(查找当前的最高优先级/队头元素是什么),merge(将两个优先级队列合并为一个)等。测试数据:原创 2020-12-23 13:06:23 · 13960 阅读 · 0 评论 -
并发计算(Concurrent computing)【代码实现】
C#include <stdio.h>#include <unistd.h>#include <pthread.h> pthread_mutex_t condm = PTHREAD_MUTEX_INITIALIZER;pthread_cond_t cond = PTHREAD_COND_INITIALIZER;int bang = 0; #de...原创 2020-12-23 11:13:39 · 2929 阅读 · 0 评论 -
寻找给定基数中的最大左可截断素数
C#include <stdio.h>#include <gmp.h> typedef unsigned long ulong; ulong small_primes[] = {2,3,5,7,11,13,17,19,23,29,31,37,41, 43,47,53,59,61,67,71,73,79,83,89,97}; #define MAX_STACK 128mpz_t tens[MAX_STACK], value[MAX_STACK], answer;原创 2020-12-22 14:17:28 · 4083 阅读 · 0 评论 -
可截断素数(Truncatable primes)
可截断素数是当从一端连续删除数字时,得到的仍旧是素数的一个素数。举例997是左截短素数,因为997, 97 和 7 都是素数。7393是右截断素数,因为7393, 739, 73 和 7 都是素数。在可截断质数中不允许有零。目标找出小于100万的最大的左可截断和右可截断素数。相关文章:C#include <stdio.h>#include <stdlib.h>#include <string.h> #define MAX_PRIME 100000原创 2020-12-22 12:34:54 · 7139 阅读 · 0 评论 -
中国余数定理【代码实现】
C#include <stdio.h> // returns x where (a * x) % b == 1int mul_inv(int a, int b){ int b0 = b, t, q; int x0 = 0, x1 = 1; if (b == 1) return 1; while (a > 1) { q = a / b; t = b, b = a % b, a = t; t = x0, x0 = x1 - q * x0, x1 = t; }原创 2020-12-15 12:43:54 · 2967 阅读 · 0 评论 -
判断字符串中是否具有唯一字符
任务描述:给出一个字符串(可能为空字符串)输出检测的字符串及其长度空字符串是唯一的检测顺序为自左向右输出该字符串中的字符是否唯一,若不唯一指出相同的字符及其在字符串中的位置,并显示其十六进制值使用以下五个测试用例:长度为0的字符串:长度为1的字符串(标点句号):.长度为6的字符串:abcABC长度为7的字符串(中间包含空格):XYZ ZYX长度为36的字符串(字母"O...原创 2020-10-24 08:44:59 · 16683 阅读 · 0 评论 -
百囚徒问题(100 prisoners problem)
该问题由丹麦计算机科学家Peter Bro Miltersen于2003年首次提出。问题描述在监狱中有100名囚犯,被编号为1-100号。典狱长决定给囚犯们一次特赦的机会,条件是通过一项挑战。在一个房间中放着一个有100个抽屉的橱柜,里面随机放着与囚犯编号对应的1-100的号码牌。挑战开始后,每个囚犯依次进入该房间,打开不超过半数的抽屉,并从中找到与自己对应的号码则为成功,每名囚犯出去时该橱柜...原创 2020-04-30 11:09:59 · 13796 阅读 · 0 评论 -
Canny边缘检测算法(Canny edge detector)
Canny边缘检测算子是澳洲计算机科学家约翰·坎尼(John F. Canny)于1986年开发出来的一个多级边缘检测算法。算法步骤1. 降噪任何边缘检测算法都不可能在未经处理的原始数据上很好地处理,所以第一步是对原始数据与高斯平滑模板作卷积,得到的图像与原始图像相比有些轻微的模糊(blurred)。这样,单独的一个像素噪声在经过高斯平滑的图像上变得几乎没有影响。2. 寻找图像中的亮度梯度...原创 2020-04-17 14:35:33 · 17462 阅读 · 0 评论 -
并行计算(Parallel calculations)【代码实现】
假设有一组数字,我们希望找到最大的最小素因数。为了加快搜索速度,因式分解应该使用单独的线程或进程并行执行,以充分利用CPU的多个核。C使用gcc -Wall -std=c99 -fopenmp编译,其中需要gcc 4.2或更高版本。#include <stdio.h>#include <omp.h>//Using OpenMPint main(){ ...原创 2020-03-19 21:15:10 · 4568 阅读 · 0 评论 -
语法分析器(syntax analyzer)【Python实现】
from __future__ import print_functionimport sys, shlex, operator tk_EOI, tk_Mul, tk_Div, tk_Mod, tk_Add, tk_Sub, tk_Negate, tk_Not, tk_Lss, tk_Leq, tk_Gtr, \tk_Geq, tk_Eql, tk_Neq, tk_Assign, tk_A...原创 2020-03-10 10:44:12 · 4007 阅读 · 0 评论 -
语法分析器(syntax analyzer)【Perl实现】
【代码】语法分析器(syntax analyzer)【Perl实现】原创 2020-03-10 10:43:29 · 7538 阅读 · 1 评论 -
语法分析器(syntax analyzer)【Java实现】
import java.io.File;import java.io.FileNotFoundException;import java.util.Scanner;import java.util.StringTokenizer;import java.util.List;import java.util.ArrayList;import java.util.Map;import j...原创 2020-03-10 10:42:46 · 5771 阅读 · 0 评论 -
语法分析器(syntax analyzer)【Go实现】
package main import ( "bufio" "fmt" "log" "os" "strconv" "strings") type TokenType int const ( tkEOI TokenType = iota tkMul tkDiv tkMod tkAdd tkS...原创 2020-03-10 10:41:49 · 3330 阅读 · 0 评论 -
语法分析器(syntax analyzer)【C实现】
#include <stdio.h>#include <stdlib.h>#include <string.h>#include <stdarg.h>#include <stdbool.h>#include <ctype.h> #define NELEMS(arr) (sizeof(arr) / sizeof(a...原创 2020-03-10 10:40:17 · 2711 阅读 · 0 评论 -
Gray code(格雷码)【代码实现】
Cint gray_encode(int n) { return n ^ (n >> 1);} int gray_decode(int n) { int p = n; while (n >>= 1) p ^= n; return p;}示例:#include <stdio.h> /* Simple bool f...原创 2020-01-15 12:53:30 · 13266 阅读 · 0 评论 -
LZW(Lempel-Ziv-Welch)算法【代码实现】
C#include <stdio.h>#include <stdlib.h>#include <string.h>#include <stdint.h>#include <unistd.h>#include <fcntl.h>#include <sys/types.h>#include <sy...原创 2020-01-13 21:18:36 · 9623 阅读 · 0 评论 -
词法分析器(Lexical Analyzer)【Python实现】
正文内容from __future__ import print_functionimport sys # following two must remain in the same order tk_EOI, tk_Mul, tk_Div, tk_Mod, tk_Add, tk_Sub, tk_Negate, tk_Not, tk_Lss, tk_Leq, tk_Gtr, \tk_...原创 2019-12-16 19:13:47 · 8296 阅读 · 0 评论 -
词法分析器(Lexical Analyzer)【JavaScript实现】
正文内容/* Token: type, value, line, pos*/ const TokenType = { Keyword_if: 1, Keyword_else: 2, Keyword_print: 3, Keyword_putc: 4, Keyword_while: 5, Op_add: 6, Op_and: 7, Op_assign: 8, Op_d...原创 2019-12-16 19:13:12 · 2935 阅读 · 1 评论 -
词法分析器(Lexical Analyzer)【Java实现】
正文内容import java.io.File;import java.io.FileNotFoundException;import java.util.HashMap;import java.util.Map;import java.util.Scanner; public class Lexer { private int line; private int p...原创 2019-12-16 19:12:29 · 3476 阅读 · 0 评论 -
词法分析器(Lexical Analyzer)【Go实现】
正文内容package main import ( "bufio" "fmt" "log" "os") type TokenType int const ( tkEOI TokenType = iota tkMul tkDiv tkMod tkAdd tkSub tkNegate tkN...原创 2019-12-16 19:11:56 · 2489 阅读 · 0 评论 -
词法分析器(Lexical Analyzer)【C#实现】
正文内容using System;using System.IO;using System.Linq;using System.Collections.Generic; namespace Rosetta { public enum TokenType { End_of_input, Op_multiply, Op_divide, Op_mod, Op_...原创 2019-12-16 19:11:20 · 3365 阅读 · 0 评论 -
词法分析器(Lexical Analyzer)【C实现】
正文内容#include <stdlib.h>#include <stdio.h>#include <stdarg.h>#include <ctype.h>#include <string.h>#include <errno.h>#include <stdbool.h>#include <li...原创 2019-12-16 19:10:21 · 3759 阅读 · 0 评论 -
CRC-32【代码实现】
C#include <inttypes.h>#include <stdio.h>#include <string.h> uint32_trc_crc32(uint32_t crc, const char *buf, size_t len){ static uint32_t table[256]; static int have_table = ...原创 2019-11-10 18:07:42 · 11579 阅读 · 1 评论 -
SHA-1算法【代码实现】
C#include <stdio.h>#include <stdlib.h>#include <string.h>#include <openssl/sha.h> int main(){ int i; unsigned char result[SHA_DIGEST_LENGTH]; const char *string = ...原创 2019-09-13 15:39:47 · 9344 阅读 · 3 评论 -
判断输入的字符串是否为数字
目标创建一个函数,使其接收一个字符串并判断该字符串是否为数字。代码实现C#include <ctype.h>#include <stdlib.h>int isNumeric (const char * s){ if (s == NULL || *s == '\0' || isspace(*s)) return 0; char * p...原创 2019-11-08 18:37:44 · 9818 阅读 · 0 评论 -
Base64 编码【代码实现】
C#include <stdio.h>#include <stdlib.h>#include <resolv.h>#include <fcntl.h>#include <unistd.h>#include <sys/types.h>#include <sys/stat.h>#include <...原创 2019-08-06 16:16:19 · 8833 阅读 · 0 评论 -
排序算法——选择排序【代码实现】
ActionScriptfunction selectionSort(input: Array):Array { //find the i'th element for (var i:uint = 0; i < input.length; i++) { //set minIndex to an arbitrary value var minIndex:uint=i; //f...原创 2019-06-09 11:23:32 · 11012 阅读 · 0 评论 -
SHA-256算法【代码实现】
C#include <stdio.h>#include <string.h>#include <openssl/sha.h> int main (void) { const char *s = "Rosetta code"; unsigned char *d = SHA256(s, strlen(s), 0); int i; for (i ...原创 2019-09-13 15:39:23 · 9795 阅读 · 0 评论 -
K-d tree【代码实现】
C#include <stdio.h>#include <stdlib.h>#include <string.h>#include <math.h>#include <time.h> #define MAX_DIM 3struct kd_node_t{ double x[MAX_DIM]; struct k...原创 2019-09-12 08:34:12 · 1736 阅读 · 1 评论 -
毕达哥拉斯树(Pythagoras tree)【代码实现】
C#include<graphics.h>#include<stdlib.h>#include<stdio.h>#include<time.h> typedef struct{ double x,y;}point; void pythagorasTree(point a,point b,int times){ point c...原创 2019-09-12 08:30:06 · 4450 阅读 · 0 评论 -
排序算法——鸡尾酒排序(Cocktail sort)【代码实现】
伪代码function cocktailSort( A : list of sortable items ) do swapped := false for each i in 0 to length( A ) - 2 do if A[ i ] > A[ i+1 ] then // test whether the two ...原创 2019-06-11 16:06:36 · 3899 阅读 · 0 评论 -
排序算法——圆形排序(Circle Sort)【代码实现】
伪代码function circlesort (index lo, index hi, swaps) { if lo == hi return (swaps) high := hi low := lo mid := int((hi-lo)/2) while lo < hi { if (value at lo) > (value at hi)...原创 2019-06-11 10:27:25 · 8863 阅读 · 0 评论 -
排序算法——全排序(Permutation sort)【代码实现】
ActionScript//recursively builds the permutations of permutable, appended to front, and returns the first sorted permutation it encountersfunction permutations(front:Array, permutable:Array):Array {...原创 2019-06-16 15:45:47 · 8964 阅读 · 0 评论 -
排序算法——耐心排序(Patience sort)【代码实现】
C#include<stdlib.h>#include<stdio.h> int* patienceSort(int* arr,int size){ int decks[size][size],i,j,min,pickedRow; int *count = (int*)calloc(sizeof(int),size),*sortedArr = (int*)m...原创 2019-06-17 22:24:55 · 4242 阅读 · 0 评论 -
排序算法——煎饼排序(Pancake sort)【代码实现】
Cint pancake_sort(int *list, unsigned int length){ //If it's less than 2 long, just return it as sorting isn't really needed... if(length<2) return 0; int i,a,max_num_pos,mo...原创 2019-06-16 22:23:31 · 3206 阅读 · 0 评论 -
排序算法——堆排序【代码实现】
伪代码function heapSort(a, count) is input: an unordered array a of length count (first place a in max-heap order) heapify(a, count) end := count - 1 while end > 0 do (swap t...原创 2019-06-15 20:15:55 · 2428 阅读 · 0 评论 -
排序算法——猴子排序(Bogosort)【代码实现】
伪代码while not InOrder(list) do Shuffle(list)done原创 2019-06-10 11:24:02 · 8563 阅读 · 0 评论