-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontent.json
1 lines (1 loc) · 13.9 KB
/
content.json
1
{"pages":[],"posts":[{"title":"6_array_data_processing_2","text":"6.数组处理批量数据6.4 将整型数组元素行列位置对调1234567891011121314151617181920212223242526#include<stdio.h>int main() { int a[2][3]={{1,2,3},{4,5,6}}; int b[3][2],i,j; printf("array a:\\n"); for(i=0;i<=1;i++) //遍历二维数组a 元素并赋值于b;遍历行 { for (j=0;j<=2;j++) //遍历数组a 列 { printf("%5d",a[i][j]); b[j][i]=a[i][j]; //数组a中元素与数组b中 元素对调(行、列) } printf("\\n"); } printf("array b:\\n"); for(i=0;i<=2;i++) //遍历数组b,循环结构for遍历行 { for(j=0;j<=1;j++) //遍历列 printf("%5d",b[i][j]); printf("\\n"); } return 0;} 6.5 将整型数组中最大值元素及相应行列位置输出12345678910111213141516#include<stdio.h>int main(){ int i,j,row=0,colum=0,max; int a[3][4]={{1,2,3,4},{9,8,7,6},{-10,10,-5,2}}; max=a[0][0]; for(i=0;i<=2;i++) //数组遍历,行遍历 for(j=0;j<=3;j++) // 数组遍历,列遍历 if(a[i][j]>max) //“打擂台”算法 {max=a[i][j]; row=i; colum=j; } printf("max=%d\\nrow=%d\\ncolum=%d\\n",max,row,colum); //最大值输出、行/列号输出 return 0; } 6.6 字符数组输出特定字符12345678910#include<stdio.h>int main(){ char c[15]={'I',' ','a','m',' ','a',' ','s','t','u','d','e','n','t','.'}; int i; for(i=0;i<15;i++) printf("%c",c[i]); printf("\\n"); return 0; } 6.7 用星号(*)输出钻石图案12345678910111213#include<stdio.h>int main(){ char diamond[][5]={{' ',' ','*'},{' ','*',' ','*',' '},{'*',' ',' ',' ','*'},{' ','*',' ','*',' '},{' ',' ','*',' ',' '}}; //定义字符数组元素初始值,5行5列 int i,j; for(i=0;i<5;i++) //遍历数组元素,行遍历 { for(j=0;j<5;j++) //遍历数组元素,列遍历 printf("%c",diamond[i][j]); printf("\\n"); } return 0;}","link":"/2020/10/08/6-array-data-processing-2/"},{"title":"6_array_data_processing","text":"6.数组处理批量数据6.1 为数组赋值0~9,并将数组元素逆序输出123456789101112#include<stdio.h>int main(){ int i,a[10]; //定义整型变量i ,整型数组a for(i=0;i<=9;i++) //循环for为数组元素赋值 a[i]=i; for(i=9;i>=0;i--) //循环for 将数组元素逆序输出 printf("%d",a[i]); printf("\\n"); return 0;} 6.2 输出斐波那契数列第2~21项(斐波那契数列:0,1,1,2,3,5…)12345678910111213141516171819#include<stdio.h>int main(){ int i; int f[20]={1,1}; //定义整型数组,第1,2项均为1 for(i=2;i<20;i++) //循环结构for为整型数组第3至20项赋值 f[i]=f[i-2]+f[i-1]; for(i=0;i<20;i++) { if(i%5==0) printf("\\n"); printf("%12d",f[i]); //输出数组元素值,每数值占12列且右对齐 } printf("\\n"); return 0;} 6.3 自定义10个数值,将数值按升序形式输出(冒泡排序法)1234567891011121314151617181920#include<stdio.h>int main(){ int a[10]; int i,j,t; printf("input 10 numbers :\\n"); for(i=0;i<10;i++) //循环结构for 读取数据并存储 scanf("%d",&a[i]); printf("\\n"); for(j=0;j<9;j++) //重复趟数总计9次,遍历每趟 for(i=0;i<9-j;i++) // 每趟内遍历数组元素 if(a[i]>a[i+1]) {t=a[i];a[i]=a[i+1];a[i+1]=t;} //条件判断,若前一项大于后一项,进行数值交换 printf("the sorted numbers :\\n"); for(i=0;i<10;i++) //循环结构输出sorted 后的数组元素 printf("%d",a[i]); printf("\\n"); return 0; }","link":"/2020/10/07/6-array-data-processing/"},{"title":"DS_1_1_Recursion","text":"数据结构_chapter 1_1.1_递归(recursion)1. 递归实现阶乘12345678910111213141516#include<stdio.h>double factorial(unsigned int number) //数据类型 double 可用于阶乘运算较宽数值范围乘积的存储{ if(number<=0){ //此处应修改为: number<=1 ,若为 number<=0, 则会重复一次乘1操作 return 1; } return number*factorial(number-1); } int main(){ unsigned int number; scanf("%d",&number); printf("%d的阶乘结果为:%f\\n",number,factorial(number)); return 0; } 2. 递归实现斐波那契数列前 ‘n’ 项输出123456789101112131415161718192021222324#include<stdio.h>int fibonaci(int i){ if(i==1) //数列第一项 { return 0; } if(i==2) //数列第二项 { return 1; } return fibonaci(i-1) + fibonaci(i-2);}int main(){ int number,i; scanf("%d",&number); for(i=1;i<=number;i++) { printf("%d\\t\\n",fibonaci(i)); } return 0;} 3. 递归实现从’1~n’整型数据顺序输出非递归方法: 1234567891011121314151617#include<stdio.h>void PrintN(int N){ int i; for(i=1;i<=N;i++) printf("%d\\n",i); return;}int main(){ int N; scanf("%d",&N); PrintN(N); return 0;} 递归方法: 123456789101112131415#include<stdio.h>void PrintN(int N){ if(N>0){ PrintN(N-1); printf("%d\\n",N); }}int main(){ int N; scanf("%d",&N); PrintN(N); return 0;} or 1234567891011121314151617#include<stdio.h>void PrintN(int N);int main(){ int N; scanf("%d",&N); PrintN(N); return;}void PrintN(int N){ if(N>0){ PrintN(N-1); printf("%d\\n",N); }}","link":"/2020/10/10/DS-1-1-Recursion/"},{"title":"Hexo_github_搭建个人博客","text":"个人博客搭建(github + nodejs + hexo + theme (3-Hexo)):1.git 下载与安装git 简介:Git (/ɡɪt/)is a distributed version-control system(分布式版本控制系统) for tracking changes in source code during software development.It is designed for coordinating work among programmers, but it can be used to track changes in any set of files. Its goals include speed, data integrity, and support for distributed, non-linear workflows[clarification needed]. The reasons why we use git git 下载与安装:you can download : website the installtion just follows the defalut. git 使用:git 中文教程: 廖雪峰git 教程 2.Nodejs 下载与安装nodejs 简介:As an asynchronous event-driven JavaScript runtime, Node.js is designed to build scalable network applications. In the following “hello world” example, many connections can be handled concurrently. Upon each connection, the callback is fired, but if there is no work to be done, Node.js will sleep. 1234567891011121314151617const http = require('http');const hostname = '127.0.0.1';const port = 3000;const server = http.createServer((req, res) => { res.statusCode = 200; res.setHeader('Content-Type', 'text/plain'); res.end('Hello World');});server.listen(port, hostname, () => { console.log(`Server running at http://${hostname}:${port}/`);}); nodejs 下载与安装:根据操作系统选择相应 ‘source code’ 或者 ‘pre-built installer’安装过程保持默认设置即可 nodejs 使用:官方手册 documentation 3.Hexo 下载与安装Hexo 简介:Hexo is a fast, simple and powerful blog framework. You write posts in Markdown (or other markup languages) and Hexo generates static files with a beautiful theme in seconds. Hexo 下载与安装:3.1. 命令行安装12npm install hexo-cli -g windows 系统可能出现报错: win32 不支持 fsevents , SKIPPING OPTIONAL DEPENDENCY, 不影响 hexo 基本功能json optional dependencies 1234WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@~2.1.2 (node_modules\\hexo-cli\\node_modules\\chokidar\\node_modules\\fsevents):npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for [email protected]: wanted {"os":"darwin","arch":"any"} (current: {"os":"win32","arch":"x64"}) 3.2.检查 hexo 是否已经安装成功:1hexo version 123456789101112131415161718hexo-cli: 4.2.0os: Windows_NTnode: 12.18.4v8: 7.8.279.23-uv: 1.38.0zlib: 1.2.11brotli: 1.0.7ares: 1.16.0modules: 72nghttp2: 1.41.0napi: 6llhttp: 2.1.2http_parser: 2.openssl: 1.1.1gcldr: 37.0icu: 67.1tz: 2019cunicode: 13.0 3.3.初始化(文件克隆 hexo-starter、Submodule themes/landscape、;安装依赖)1hexo init username.github.io 初始化成功提醒: 1INFO Start blogging with Hexo! 3.4.测试 本地服务 是否可以启动1hexo server server 成功提醒INFO : 1234INFO Validating configINFO Start processingINFO Hexo is running at http://localhost:4000 . Press Ctrl+C to stop.INFO Bye! 3.5. 生成 SSH Keys, 并添加至 github, 测试 本地与 github 通信是否成功1ssh-keygen -t rsa -C "***@***.com" KEY 添加方法 : Github –> settings —> SSH keys setting 通信测试 : 1ssh -T [email protected] 1Hi ***! You've successfully authenticated, but GitHub does not provide shell access. or 1$ ssh [email protected] 12Hi ******! You've successfully authenticated, but GitHub does not provide shell access.Connection to github.com closed. 3.6. 配置 SSH 服务 、_config.yml文件 : 如未配置,则每次 hexo deploy 均需要输入用户名及密码:12$ git config --global user.name "******"// github用户名$ git config --global user.email "******"// github注册邮箱 _config.yml文件更改为: 1234deploy: type: git repository: [email protected]:username/username.github.io.git branch: master 不当写法:此种写法为 hexo2.* 版本书写规则,执行 hexo d 时会导致报错 Deployer not found: github or Deployer not found: git , 可通过安装插件解决 npm install hexo-deployer-git --save 1234deploy: type: github repository: https://github.com/username/username.github.io.git branch: master 4. 域名解析:添加域名解析后,可使个性化域名指向博客 。为域名添加两条记录:主机记录(@ ; www); 记录类型(A ; CNAME); 解析线路 (默认 ; 默认) ; 记录值 ( IP ; ***.github.io) ; TTL (10min ;10min) IP 获取方式 : 1ping ***.github.com 5. Hexo 使用教程(主题更换):官方教程3-hexo yelog","link":"/2020/10/07/Hexo-and-Github-Based-Personal-Blogs/"},{"title":"","text":"Using R to Measure Distance1.question description:using R code to calculate the distance, such as “euclidean” “chebyshev” “cosine” 2.solutions :using the key words “R package” and “distance” searching for the packages, andwe got the package of philentropy 2.1.code :#install package in console install.packages("philentropy")#load the packagelibrary(philentropy)#define the vectors needed calculatingv1 <- (1,3,4)v2 <- (2,3,2)#calculate with the default parameters#manhattan distance,euclidean,cosine,lin.cor(pearson)distance(x, method = "manhattan")distance(x, method = "euclidean") 2.2.output :12345678910111213141516171819Metric: 'manhattan'; comparing: 2 vectors.manhattan 3 > distance(x, method = "euclidean")Metric: 'euclidean'; comparing: 2 vectors.euclidean 2.236068 > distance(x, method = "chebyshev")Metric: 'chebyshev'; comparing: 2 vectors.chebyshev 2 > distance(x, method = "cosine")Metric: 'cosine'; comparing: 2 vectors. cosine 0.9037378 > lin.cor(A,B) pearson 0.1889822 3.supplyment materials:the difference between different type of distance 3.1. euclideanhttps://en.wikipedia.org/wiki/Euclidean_distance In mathematics, the Euclidean distance between two points in Euclidean space is a number, the length of a line segment between the two points. It can be calculated from the Cartesian coordinates of the points using the Pythagorean theorem, and is occasionally called the Pythagorean distance. 3.2. cosine distancecosine distance (or cosine similarity, angular cosine distance, angular cosine similarity) between two variables.https://en.wikipedia.org/wiki/Cosine_similarity Cosine similarity is a measure of similarity between two non-zero vectors of an inner product space. It is defined to equal the cosine of the angle between them, which is also the same as the inner product of the same vectors normalized to both have length 1. The cosine of 0° is 1, and it is less than 1 for any angle in the interval (0, π] radians. It is thus a judgment of orientation and not magnitude: two vectors with the same orientation have a cosine similarity of 1, two vectors oriented at 90° relative to each other have a similarity of 0, and two vectors diametrically opposed have a similarity of -1, independent of their magnitude. The cosine similarity is particularly used in positive space, where the outcome is neatly bounded in {\\displaystyle [0,1]}[0,1]. 3.3. cosine distancehttps://medium.com/swlh/is-correlation-distance-a-metric-5a383973978f#:~:text=Correlation%20distance%20is%20a%20popular,as%20d%3D1%2Dr. Correlation distance is a popular way of measuring the distance between two random variables with finite variances¹. If the correlation² between two random variables is r, then their correlation distance is defined as d=1-r. However, a proper distance measure needs to have a few properties, i.e. should be a metric, and it is not trivial whether correlation distance has these properties. In this note, we ask whether correlation distance is a metric or not.","link":"/2020/11/23/Using-R-to-Calculating-the-Distance/"}],"tags":[{"name":"C","slug":"C","link":"/tags/C/"},{"name":"array","slug":"array","link":"/tags/array/"},{"name":"recursion","slug":"recursion","link":"/tags/recursion/"},{"name":"hexo","slug":"hexo","link":"/tags/hexo/"},{"name":"github","slug":"github","link":"/tags/github/"},{"name":"statistics","slug":"statistics","link":"/tags/statistics/"},{"name":"R","slug":"R","link":"/tags/R/"},{"name":"Distance","slug":"Distance","link":"/tags/Distance/"}],"categories":[{"name":"Programming","slug":"Programming","link":"/categories/Programming/"},{"name":"Data Structure","slug":"Data-Structure","link":"/categories/Data-Structure/"},{"name":"Tools","slug":"Tools","link":"/categories/Tools/"},{"name":"C","slug":"Programming/C","link":"/categories/Programming/C/"},{"name":"R","slug":"R","link":"/categories/R/"},{"name":"C","slug":"Data-Structure/C","link":"/categories/Data-Structure/C/"},{"name":"Blog","slug":"Tools/Blog","link":"/categories/Tools/Blog/"}]}