├── .DS_Store ├── .gitattributes ├── .gitignore ├── .vscode └── launch.json ├── README.md ├── articals ├── c++ │ ├── class.md │ ├── function.md │ ├── oop.md │ ├── reload.md │ ├── str_map_arr.md │ └── var.md ├── c │ ├── Demo │ │ ├── argv[2] │ │ ├── bug1.c │ │ ├── mywords │ │ ├── test.c │ │ ├── test.exe │ │ ├── test10.c │ │ ├── test10.exe │ │ ├── test11.c │ │ ├── test11.exe │ │ ├── test12.c │ │ ├── test12.exe │ │ ├── test13.c │ │ ├── test13.exe │ │ ├── test14.c │ │ ├── test14.exe │ │ ├── test15.c │ │ ├── test15.exe │ │ ├── test16.c │ │ ├── test16.exe │ │ ├── test17.c │ │ ├── test17.exe │ │ ├── test18.c │ │ ├── test18.exe │ │ ├── test19.c │ │ ├── test19.exe │ │ ├── test2.c │ │ ├── test2.exe │ │ ├── test20.c │ │ ├── test20.exe │ │ ├── test21.c │ │ ├── test21.exe │ │ ├── test22.c │ │ ├── test22.exe │ │ ├── test23.c │ │ ├── test23.exe │ │ ├── test24.c │ │ ├── test24.exe │ │ ├── test25.c │ │ ├── test25.exe │ │ ├── test26.c │ │ ├── test26.exe │ │ ├── test27.c │ │ ├── test27.exe │ │ ├── test28.c │ │ ├── test28.exe │ │ ├── test29.c │ │ ├── test29.exe │ │ ├── test3.c │ │ ├── test3.exe │ │ ├── test30.c │ │ ├── test30.exe │ │ ├── test31.c │ │ ├── test31.exe │ │ ├── test32.c │ │ ├── test32.exe │ │ ├── test33.c │ │ ├── test33.exe │ │ ├── test34.c │ │ ├── test34.exe │ │ ├── test35.c │ │ ├── test35.exe │ │ ├── test36.c │ │ ├── test36.exe │ │ ├── test37.c │ │ ├── test37.exe │ │ ├── test38.c │ │ ├── test38.exe │ │ ├── test39.c │ │ ├── test39.exe │ │ ├── test4.c │ │ ├── test4.exe │ │ ├── test40.c │ │ ├── test40.exe │ │ ├── test41.c │ │ ├── test41.exe │ │ ├── test42.c │ │ ├── test42.exe │ │ ├── test43.c │ │ ├── test43.exe │ │ ├── test44.c │ │ ├── test44.exe │ │ ├── test45.c │ │ ├── test45.exe │ │ ├── test46.c │ │ ├── test46.exe │ │ ├── test47.c │ │ ├── test47.exe │ │ ├── test48.c │ │ ├── test48.exe │ │ ├── test49.c │ │ ├── test49.exe │ │ ├── test5.c │ │ ├── test5.exe │ │ ├── test50.c │ │ ├── test50.exe │ │ ├── test51.c │ │ ├── test51.exe │ │ ├── test52.c │ │ ├── test52.exe │ │ ├── test53.c │ │ ├── test53.exe │ │ ├── test54.c │ │ ├── test54.exe │ │ ├── test55.c │ │ ├── test55.exe │ │ ├── test56.c │ │ ├── test56.exe │ │ ├── test57.c │ │ ├── test57.exe │ │ ├── test58.c │ │ ├── test58.exe │ │ ├── test59.c │ │ ├── test59.exe │ │ ├── test6.c │ │ ├── test6.exe │ │ ├── test60.c │ │ ├── test60.exe │ │ ├── test61.c │ │ ├── test61.exe │ │ ├── test62.c │ │ ├── test62.exe │ │ ├── test63.c │ │ ├── test64.c │ │ ├── test65.c │ │ ├── test65.exe │ │ ├── test66.c │ │ ├── test66.exe │ │ ├── test67.c │ │ ├── test67.exe │ │ ├── test68.c │ │ ├── test68.exe │ │ ├── test69.c │ │ ├── test69.exe │ │ ├── test7.c │ │ ├── test7.exe │ │ ├── test70.c │ │ ├── test70.exe │ │ ├── test71.c │ │ ├── test71.exe │ │ ├── test72.c │ │ ├── test72.exe │ │ ├── test73.c │ │ ├── test73.exe │ │ ├── test74.c │ │ ├── test74.exe │ │ ├── test75.c │ │ ├── test75.exe │ │ ├── test76.c │ │ ├── test76.exe │ │ ├── test77.c │ │ ├── test78.c │ │ ├── test78.exe │ │ ├── test79.c │ │ ├── test79.exe │ │ ├── test8.c │ │ ├── test8.exe │ │ ├── test80.c │ │ ├── test81.c │ │ ├── test81.exe │ │ ├── test82.c │ │ ├── test82.exe │ │ ├── test83.c │ │ ├── test83.exe │ │ ├── test84.c │ │ ├── test85.c │ │ ├── test86.c │ │ ├── test86.exe │ │ ├── test87.c │ │ ├── test88.c │ │ ├── test88.exe │ │ ├── test89.c │ │ ├── test89.exe │ │ ├── test9.c │ │ ├── test9.exe │ │ ├── test90.c │ │ ├── test91.c │ │ ├── test91.h │ │ ├── test92.c │ │ ├── test92.exe │ │ ├── test93.c │ │ ├── test94.c │ │ ├── test94.exe │ │ ├── test95.c │ │ ├── test95.exe │ │ ├── test96.c │ │ ├── test97.c │ │ ├── test97.exe │ │ ├── test98.c │ │ ├── test98.exe │ │ ├── test99.c │ │ ├── testDice_d.c │ │ ├── testDice_d.exe │ │ ├── testFgets.c │ │ ├── testFgets.exe │ │ ├── testFgets2.c │ │ ├── testFgets2.exe │ │ ├── testFgets3.c │ │ ├── testFgets3.exe │ │ ├── testFileIO.c │ │ ├── testFileIO.exe │ │ ├── testGets.c │ │ ├── testGets.exe │ │ ├── testIO.c │ │ ├── testIO.exe │ │ ├── testP02.c │ │ ├── testP02.exe │ │ ├── testPntAdd.c │ │ ├── testPntAdd.exe │ │ ├── testPo.c │ │ ├── testPo.exe │ │ ├── testPoint.c │ │ ├── testPoint.exe │ │ ├── testPrintfScanf.c │ │ ├── testPrintfScanf.exe │ │ ├── testR_d.c │ │ ├── testR_d.exe │ │ ├── testRand.c │ │ ├── testRandom.c │ │ ├── testRandom.exe │ │ ├── testRecursion.c │ │ ├── testRecursion.exe │ │ ├── testReducto.c │ │ ├── testReducto.exe │ │ ├── testScope.c │ │ ├── testStrSort.c │ │ ├── testStrSort.exe │ │ ├── testSwap.c │ │ ├── testSwap.exe │ │ ├── testToBinary.c │ │ ├── testToBinary.exe │ │ ├── words │ │ ├── words.red │ │ └── wordscp │ ├── array.md │ ├── data.md │ ├── fileIO.md │ ├── function.md │ ├── memory.md │ └── string.md ├── h5 │ ├── 0001.md │ ├── 0002.md │ └── 0003.md ├── interview │ └── 0001.md ├── js │ ├── 0001.md │ └── 0002.md ├── react │ └── 0001.md └── vue │ ├── 0001.md │ └── 0002.md ├── booknotes ├── bst.md ├── compute.md ├── demo │ ├── AVL.class.cpp │ ├── BST.class.cpp │ ├── BTNode.h │ ├── BTree.class.cpp │ ├── BinNode.h │ ├── BinTree.class.cpp │ ├── Edge.h │ ├── Graph.class.cpp │ ├── GraphMatrix.class.cpp │ ├── Lcs.cpp │ ├── Lcs.exe │ ├── List.class.cpp │ ├── ListNode.h │ ├── Node.h │ ├── PQ.class.cpp │ ├── PQ_ComplHeap.class.cpp │ ├── Queue.class.cpp │ ├── RedBlack.class.cpp │ ├── SList.class.cpp │ ├── Splay.class.cpp │ ├── Stack.class.cpp │ ├── SumI.exe │ ├── Vector.class.cpp │ ├── VectorTest.cpp │ ├── VectorTest.exe │ ├── Vertex.h │ ├── a_bubbleSort.cpp │ ├── a_convert.cpp │ ├── a_evaluate.cpp │ ├── a_fib.cpp │ ├── a_hailstone.cpp │ ├── a_paren.cpp │ ├── a_sum.cpp │ ├── a_vector.cpp │ ├── fib.exe │ ├── hailstone.exe │ ├── sort.cpp │ └── test.exe ├── graph.md ├── hash.md ├── list.md ├── proqueue.md ├── sort.md ├── string.md ├── sum.md ├── superBST.md ├── tree.md └── vector.md ├── package-lock.json ├── package.json ├── public ├── .DS_Store ├── html │ ├── demo-box-model.html │ ├── demo-display.html │ ├── demo-float.html │ ├── demo-position.html │ └── layout.css └── images │ ├── h500001001.jpg │ ├── h500001002.jpg │ ├── h500001003.jpg │ ├── h500001004.jpg │ ├── h500001005.jpg │ ├── h500001006.jpg │ ├── h500001007.jpg │ ├── h500001008.jpg │ ├── h500001009.jpg │ ├── h50001001.jpg │ ├── h50001002.jpg │ ├── h50001003.jpg │ ├── h50001004.jpg │ ├── h50001005.jpg │ ├── h50001006.jpg │ ├── h50001007.jpg │ ├── qian.jpg │ └── weixin.png ├── src ├── .DS_Store ├── README.md ├── algorithm │ ├── array │ │ ├── insert.js │ │ └── searchInsert.js │ ├── search │ │ └── binsearch.js │ ├── sort │ │ ├── bubblesort.js │ │ └── quicksort.js │ └── string │ │ └── repeat.js ├── babel │ └── tiny-compiler │ │ └── index.js ├── cryto │ └── sha256.js ├── css │ ├── box-model.html │ ├── center.html │ ├── flex.html │ ├── float.html │ ├── hairline.html │ ├── layout.html │ ├── three-layout.html │ ├── two-layout.html │ └── var.html ├── data-structure │ ├── linklist-circle.js │ ├── linklist-curd.js │ ├── linklist.js │ └── list.js ├── javascript │ ├── array.js │ ├── async_sync.js │ ├── block-scope.js │ ├── call.js │ ├── callback.js │ ├── class.js │ ├── class │ │ └── construct.js │ ├── closure │ │ ├── closure-circle.js │ │ └── proxy.js │ ├── code │ │ ├── huiwen-longest-str.js │ │ ├── is-huiwen-num.js │ │ ├── is-huiwen-string.js │ │ ├── longest-asc-str.js │ │ ├── longest-norepeat-str.js │ │ ├── merge-two-array.js │ │ ├── merge-two-lists.js │ │ ├── two-nums-2.js │ │ ├── two-nums-add.js │ │ ├── two-nums.js │ │ └── valid-parent.js │ ├── curry.js │ ├── debounce.js │ ├── dom.js │ ├── event-loop.js │ ├── event.js │ ├── flat.js │ ├── function-scope.js │ ├── function-this.js │ ├── hoisting.js │ ├── implement │ │ ├── apply.js │ │ ├── async.js │ │ ├── bind.js │ │ ├── class.js │ │ ├── compose.js │ │ ├── copy.js │ │ ├── inherit.js │ │ ├── new.js │ │ ├── pipe.js │ │ ├── promise.js │ │ ├── reduce.js │ │ └── sleep.js │ ├── inherit.js │ ├── map.js │ ├── new.js │ ├── object │ │ ├── copy.js │ │ ├── enum.js │ │ ├── exist.js │ │ ├── get-set.js │ │ ├── iterator.js │ │ ├── property-desciptor.js │ │ └── traverse.js │ ├── promise.js │ ├── proto.js │ ├── proxy │ │ └── base.js │ ├── recursion │ │ └── base.js │ ├── regExp.js │ ├── scope.js │ ├── set.js │ ├── set │ │ └── set.js │ ├── sleep.js │ ├── string.js │ ├── this.js │ ├── throttle.js │ ├── type.js │ └── uniqu.js ├── json │ ├── data.json │ ├── distinct_data.json │ ├── manage__origin_data.json │ ├── manage_cata_data.js │ └── manage_cata_data.json ├── koa │ ├── db │ │ └── index.js │ └── index.js ├── leetcode │ ├── 1.两数之和.js │ ├── 13.罗马数字转整数.js │ ├── 14.最长公共前缀.js │ ├── 165.比较版本号.js │ ├── 2.两数相加.js │ ├── 20.有效的括号.js │ ├── 21.合并两个有序链表.js │ ├── 26.删除排序数组中的重复项.js │ ├── 27.移除元素.js │ ├── 28.实现-str-str.js │ ├── 3.无重复字符的最长子串.js │ ├── 341.扁平化嵌套列表迭代器.js │ ├── 35.搜索插入位置.js │ ├── 38.外观数列.js │ ├── 53.最大子序和.js │ ├── 58.最后一个单词的长度.js │ ├── 66.加一.js │ ├── 67.二进制求和.js │ ├── 69.x-的平方根.js │ ├── 7.整数反转.js │ └── 9.回文数.js ├── linux │ └── process_manage.sh ├── node │ ├── api-test │ │ └── image.js │ ├── app │ │ ├── index.js │ │ ├── requestHandles.js │ │ ├── router.js │ │ └── server.js │ ├── file │ │ ├── file-download.js │ │ ├── file-read.js │ │ └── fileaa.jpg │ └── node-fetch │ │ └── index.js ├── question │ └── interserction.js ├── react │ ├── .DS_Store │ ├── app │ │ ├── .gitignore │ │ ├── README.md │ │ ├── package.json │ │ ├── public │ │ │ ├── favicon.ico │ │ │ ├── index.html │ │ │ ├── logo192.png │ │ │ ├── logo512.png │ │ │ ├── manifest.json │ │ │ └── robots.txt │ │ ├── src │ │ │ ├── antd-mobile │ │ │ │ ├── input.js │ │ │ │ ├── picker-demo.js │ │ │ │ ├── steps-demo.js │ │ │ │ └── steps-demo.scss │ │ │ ├── antd │ │ │ │ ├── searchDemo.js │ │ │ │ └── upload.js │ │ │ ├── assets │ │ │ │ ├── font │ │ │ │ │ └── PingFangSC-Regular.fft │ │ │ │ └── scss │ │ │ │ │ └── font.scss │ │ │ ├── components │ │ │ │ ├── count-down.js │ │ │ │ ├── steps-hooks.js │ │ │ │ ├── steps.js │ │ │ │ └── steps.scss │ │ │ ├── examples │ │ │ │ └── steps-demo.js │ │ │ ├── font │ │ │ │ └── pingfangsc-demo.js │ │ │ ├── images │ │ │ │ └── logo.svg │ │ │ ├── index.js │ │ │ ├── paratice │ │ │ │ ├── hook.js │ │ │ │ ├── index.css │ │ │ │ ├── index.js │ │ │ │ └── lasy-compontent.js │ │ │ ├── redux.js │ │ │ ├── router │ │ │ │ ├── index.js │ │ │ │ └── index.scss │ │ │ ├── serviceWorker.js │ │ │ └── setupTests.js │ │ └── yarn.lock │ ├── demo.html │ └── demo.jsx ├── shell │ └── image_filter.sh ├── typescript │ ├── js │ │ ├── class-demo.js │ │ ├── decorators-demo.js │ │ ├── demo.js │ │ ├── fn-demo.js │ │ ├── function-demo.js │ │ ├── generics-demo.js │ │ ├── interface-demo.js │ │ ├── overload-demo.js │ │ ├── type-advanced-demo.js │ │ ├── type-demo.js │ │ └── type-inference-demo.js │ └── ts │ │ ├── class-demo.ts │ │ ├── decorators-demo.ts │ │ ├── demo.ts │ │ ├── function-demo.ts │ │ ├── generics-demo.ts │ │ ├── interface-demo.ts │ │ ├── overload-demo.ts │ │ ├── tsconfig.json │ │ ├── type-advanced-demo.ts │ │ ├── type-demo.ts │ │ └── type-inference-demo.ts ├── web-api │ ├── localstorage.js │ └── sessionstorage.js └── webpack │ └── simple-webpack │ ├── buddle.js │ └── example │ ├── entry.js │ ├── message.js │ └── name.js ├── yarn-error.log └── yarn.lock /.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/suoyuesmile/suo-blog/6068b6934e0bcae9b189fcefdc6a6d3752295a29/.DS_Store -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | *.js linguist-language=JavaScript 2 | *.css linguist-language=JavaScript 3 | *.html linguist-language=JavaScript 4 | *.c linguist-language=JavaScript 5 | *.c++ linguist-language=JavaScript 6 | *.php linguist-language=JavaScript 7 | *.python linguist-language=JavaScript 8 | *.scss linguist-language=JavaScript 9 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /node_modules 2 | /json 3 | private-* -------------------------------------------------------------------------------- /.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "0.2.0", 3 | "configurations": [ 4 | { 5 | "type": "node", 6 | "request": "launch", 7 | "name": "Launch Program", 8 | "program": "${file}" 9 | } 10 | ] 11 | } -------------------------------------------------------------------------------- /articals/c++/reload.md: -------------------------------------------------------------------------------- 1 | # 重载运算符 2 | 3 | ### 理论 4 | - 来源:对于自定义的数据类型,需要和自带的运算符的相同功能的运算,实质是函数重载 5 | - 语法:operator关键词 6 | 7 | ``` 8 | Complex operator+(Complex c2){ 9 | Complex c; 10 | c.real = real + c2.real; 11 | c.imag = imag + c2.imag; 12 | return c; 13 | } 14 | ``` 15 | - 参数数量: 16 | - - 非成员函数:一元有一个运算符,二元有两个运算符,对于二元左侧传递给第一个参数,右侧传递给第二个参数 17 | - - 成员函数:左侧运算对象绑定到this指针上,运算参数对象比运算符运算对象少一个 18 | 19 | - 注意: 20 | 21 | ``` 22 | 1)只能重载已有的运算符,不能发明新的运算符 23 | 2)部分运算符既是一元又是二元,只能从参数上来判断到底重载的那个运算符 24 | 3)优先级和结合率与内置运算符保持一致 25 | 4)不能被重载的运算符:作用域运算符::,成员运算符., 点乘运算符.*,条件运算符 :? 26 | 5)不应被重载的运算符:逻辑与或运算符和逗号运算符 27 | 6)需要有与内置运算符一一样的含义有重载==就应当有!= 28 | 7)应当与内置运算符的放回类型兼容 29 | ``` 30 | - 作为成员与非成员函数 31 | 32 | ``` 33 | 准则: 34 | 1)赋值,下标,调用,成员访问运算符必须作为成员 35 | 2)复合赋值一般作为成员 36 | 3)改变对象状态的,或与类型密切相关的,递增,递减,解引用之类的一般作为成员 37 | 4)具有对称型的运算符可能转换任意一端的运算对象,算术,相等,关系和位运算等作为非成员 38 | ``` 39 | 40 | 41 | ### 输入输出:必须是非成员函数 42 | 43 | ``` 44 | ostream &operator<<(ostream &os, const Sale_data &item){ 45 | os << item.isbn() << " " << item.units_sold << endl; 46 | return os; 47 | } 48 | ``` 49 | 50 | ### 赋值 51 | 52 | ### 下标 53 | 54 | ### 递增递减 55 | 56 | ### 成员访问 57 | 58 | ### 函数调用 59 | -------------------------------------------------------------------------------- /articals/c/Demo/argv[2]: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/suoyuesmile/suo-blog/6068b6934e0bcae9b189fcefdc6a6d3752295a29/articals/c/Demo/argv[2] -------------------------------------------------------------------------------- /articals/c/Demo/bug1.c: -------------------------------------------------------------------------------- 1 | #include 2 | int alpha(char); 3 | int main(){ 4 | char ch; 5 | while( (ch = getchar()) != EOF ) { 6 | printf("location: %d\n", alpha(ch) ); 7 | while( getchar() != '\n') 8 | continue; 9 | } 10 | return 0; 11 | } 12 | 13 | int alpha(char ch){ 14 | if(ch >= 65 && ch <= 90) 15 | { 16 | printf("%c is upper alpha\n", ch); 17 | ch -= 64; 18 | } 19 | else if(ch >=97 && ch <= 122) 20 | { 21 | ch -= 96; 22 | printf("%c is lower alpha\n", ch); 23 | } 24 | else{ 25 | ch = -1; 26 | printf("%c is not alpha\n", ch); 27 | } 28 | return ch; 29 | } -------------------------------------------------------------------------------- /articals/c/Demo/mywords: -------------------------------------------------------------------------------- 1 | 5.3 6.2 3.6 5.6 7.9 2 | 5.6 3.9 1.5 6.9 4.8 3 | 4.1 56.6 23.7 56.1 18.6 -------------------------------------------------------------------------------- /articals/c/Demo/test.c: -------------------------------------------------------------------------------- 1 | #include 2 | /** 3 | * @return 4 | * @Author Suoyue 5 | * @DateTime 2017-08-21 6 | */ 7 | int main(){ 8 | printf("shao suo\n"); 9 | printf("shao\nsuo\n"); 10 | printf("shao "); 11 | printf("suo\n"); 12 | return 0; 13 | } 14 | //anything be careful 15 | -------------------------------------------------------------------------------- /articals/c/Demo/test.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/suoyuesmile/suo-blog/6068b6934e0bcae9b189fcefdc6a6d3752295a29/articals/c/Demo/test.exe -------------------------------------------------------------------------------- /articals/c/Demo/test10.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(){ 4 | int a = 66; 5 | printf("ASCII = %c\n", a); 6 | return 0; 7 | } -------------------------------------------------------------------------------- /articals/c/Demo/test10.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/suoyuesmile/suo-blog/6068b6934e0bcae9b189fcefdc6a6d3752295a29/articals/c/Demo/test10.exe -------------------------------------------------------------------------------- /articals/c/Demo/test11.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main(){ 3 | printf("\aStartled by the sudden sound, Sally shouted,\n\"By the Great Pumpkin, what was that!\"\n"); 4 | return 0; 5 | } -------------------------------------------------------------------------------- /articals/c/Demo/test11.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/suoyuesmile/suo-blog/6068b6934e0bcae9b189fcefdc6a6d3752295a29/articals/c/Demo/test11.exe -------------------------------------------------------------------------------- /articals/c/Demo/test12.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main(){ 3 | float f; 4 | printf("Enter a floating-point value:"); 5 | scanf("%f", &f); 6 | printf("fixed-point natation:%f\n", f); 7 | printf("exponential natation:%e\n", f); 8 | printf("p natation:%.2a\n", f); 9 | return 0; 10 | } -------------------------------------------------------------------------------- /articals/c/Demo/test12.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/suoyuesmile/suo-blog/6068b6934e0bcae9b189fcefdc6a6d3752295a29/articals/c/Demo/test12.exe -------------------------------------------------------------------------------- /articals/c/Demo/test13.c: -------------------------------------------------------------------------------- 1 | #include 2 | #define YEAR_S 3.156e+7 3 | int main(){ 4 | float age; 5 | printf("please input your age:"); 6 | scanf("%f", &age); 7 | printf("your live for %.0f second \n", age * YEAR_S); 8 | return 0; 9 | } -------------------------------------------------------------------------------- /articals/c/Demo/test13.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/suoyuesmile/suo-blog/6068b6934e0bcae9b189fcefdc6a6d3752295a29/articals/c/Demo/test13.exe -------------------------------------------------------------------------------- /articals/c/Demo/test14.c: -------------------------------------------------------------------------------- 1 | #include 2 | #define WATER_W 3.0e-23 3 | #define KATUO_W 950 4 | int main(){ 5 | float n; 6 | printf("please input kuatu num:"); 7 | scanf("%f", &n); 8 | printf("water num: %e", n * KATUO_W / WATER_W); 9 | return 0; 10 | } -------------------------------------------------------------------------------- /articals/c/Demo/test14.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/suoyuesmile/suo-blog/6068b6934e0bcae9b189fcefdc6a6d3752295a29/articals/c/Demo/test14.exe -------------------------------------------------------------------------------- /articals/c/Demo/test15.c: -------------------------------------------------------------------------------- 1 | #include 2 | #define YIN_CM 2.54 3 | int main(){ 4 | float h; 5 | printf("please input your height:"); 6 | scanf("%f", &h); 7 | printf("%f\n", h * YIN_CM); 8 | return 0; 9 | } -------------------------------------------------------------------------------- /articals/c/Demo/test15.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/suoyuesmile/suo-blog/6068b6934e0bcae9b189fcefdc6a6d3752295a29/articals/c/Demo/test15.exe -------------------------------------------------------------------------------- /articals/c/Demo/test16.c: -------------------------------------------------------------------------------- 1 | #include 2 | #define PIN_CUP 2 3 | #define CUP_YAS 8 4 | #define YAS_SOU 2 5 | #define SOU_CHA 3 6 | 7 | int main(){ 8 | float cup; 9 | printf("please input cup:"); 10 | scanf("%f", &cup); 11 | printf("pin=%f,yas=%f,sou=%f,cha=%f\n", cup*PIN_CUP, cup/CUP_YAS, cup/CUP_YAS/YAS_SOU, cup/CUP_YAS/YAS_SOU/SOU_CHA); 12 | return 0; 13 | } -------------------------------------------------------------------------------- /articals/c/Demo/test16.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/suoyuesmile/suo-blog/6068b6934e0bcae9b189fcefdc6a6d3752295a29/articals/c/Demo/test16.exe -------------------------------------------------------------------------------- /articals/c/Demo/test17.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | int main(){ 4 | char fname[30]; 5 | char sname[30]; 6 | printf("please input your first name:"); 7 | scanf("%s", fname); 8 | printf("please input your second name:"); 9 | scanf("%s", sname); 10 | printf("%s,%s\n", sname, fname); 11 | return 0; 12 | } -------------------------------------------------------------------------------- /articals/c/Demo/test17.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/suoyuesmile/suo-blog/6068b6934e0bcae9b189fcefdc6a6d3752295a29/articals/c/Demo/test17.exe -------------------------------------------------------------------------------- /articals/c/Demo/test18.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main(){ 3 | char fname[30], sname[30], tip[10] = "name:"; 4 | printf("please input your first name:"); 5 | scanf("%s", fname); 6 | printf("please input your second name:"); 7 | scanf("%s", sname); 8 | printf("\"%s %s\"\n", sname, fname); 9 | printf("%-20s\"%s %s\"\n", tip, sname, fname); 10 | printf("\"%s %s\"%20s\n", sname, fname, tip); 11 | return 0; 12 | } -------------------------------------------------------------------------------- /articals/c/Demo/test18.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/suoyuesmile/suo-blog/6068b6934e0bcae9b189fcefdc6a6d3752295a29/articals/c/Demo/test18.exe -------------------------------------------------------------------------------- /articals/c/Demo/test19.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main(){ 3 | float f; 4 | scanf("%f", &f); 5 | printf("%.1f\n", f); 6 | printf("%.1e\n", f); 7 | return 0; 8 | } -------------------------------------------------------------------------------- /articals/c/Demo/test19.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/suoyuesmile/suo-blog/6068b6934e0bcae9b189fcefdc6a6d3752295a29/articals/c/Demo/test19.exe -------------------------------------------------------------------------------- /articals/c/Demo/test2.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main(){ 3 | char* name = "shaosuo"; 4 | char* address = "wuhan"; 5 | printf("name = %s, address = %s\n", name, address); 6 | return 0; 7 | } -------------------------------------------------------------------------------- /articals/c/Demo/test2.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/suoyuesmile/suo-blog/6068b6934e0bcae9b189fcefdc6a6d3752295a29/articals/c/Demo/test2.exe -------------------------------------------------------------------------------- /articals/c/Demo/test20.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main(){ 3 | float h; 4 | printf("please input your height(cm):"); 5 | scanf("%f", &h); 6 | printf("Dabbey, your are %.3f (m)\n", h/100); 7 | return 0; 8 | } -------------------------------------------------------------------------------- /articals/c/Demo/test20.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/suoyuesmile/suo-blog/6068b6934e0bcae9b189fcefdc6a6d3752295a29/articals/c/Demo/test20.exe -------------------------------------------------------------------------------- /articals/c/Demo/test21.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main(){ 3 | float speed, fsize; 4 | printf("please input download speed, file size:"); 5 | scanf("%f%f", &speed, &fsize); 6 | printf("At %.2f megabits per second, a file of %.2f megabytes downloads in %.2f seconds\n", speed, fsize, fsize/speed); 7 | return 0; 8 | } -------------------------------------------------------------------------------- /articals/c/Demo/test21.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/suoyuesmile/suo-blog/6068b6934e0bcae9b189fcefdc6a6d3752295a29/articals/c/Demo/test21.exe -------------------------------------------------------------------------------- /articals/c/Demo/test22.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | int main(){ 4 | char fname[30], sname[30]; 5 | int flen, slen; 6 | printf("please input your first name:"); 7 | scanf("%s", fname); 8 | printf("please input your second name:"); 9 | scanf("%s", sname); 10 | flen = strlen(fname); 11 | slen = strlen(sname); 12 | printf("%6s %6s\n", fname, sname); 13 | printf("%6d %6d\n", flen, slen); 14 | printf("%-6s %-6s\n", fname, sname); 15 | printf("%-6d %-6d\n", flen, slen); 16 | return 0; 17 | } -------------------------------------------------------------------------------- /articals/c/Demo/test22.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/suoyuesmile/suo-blog/6068b6934e0bcae9b189fcefdc6a6d3752295a29/articals/c/Demo/test22.exe -------------------------------------------------------------------------------- /articals/c/Demo/test23.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | int main(){ 4 | double d = 1.0/3.0; 5 | float f = 1.0/3.0; 6 | printf("%.6Lf, %.12Lf, %.18Lf\n", d, d, d); 7 | printf("%.18Lf\n", DBL_DIG); 8 | printf("%.6f, %.12f, %.18f\n", f, f, f); 9 | printf("%.18f\n", FLT_DIG); 10 | return 0; 11 | } -------------------------------------------------------------------------------- /articals/c/Demo/test23.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/suoyuesmile/suo-blog/6068b6934e0bcae9b189fcefdc6a6d3752295a29/articals/c/Demo/test23.exe -------------------------------------------------------------------------------- /articals/c/Demo/test24.c: -------------------------------------------------------------------------------- 1 | #include 2 | #define JIA_S 3.785 3 | #define YIN_KM 1.609 4 | int main(){ 5 | float s, fule; 6 | printf("please input s(yinli), fule(jialu):"); 7 | scanf("%f%f", &s, &fule); 8 | printf("result:%.1f(KM/SHENG)\n", (s/YIN_KM)/(fule*JIA_S)); 9 | return 0; 10 | } -------------------------------------------------------------------------------- /articals/c/Demo/test24.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/suoyuesmile/suo-blog/6068b6934e0bcae9b189fcefdc6a6d3752295a29/articals/c/Demo/test24.exe -------------------------------------------------------------------------------- /articals/c/Demo/test25.c: -------------------------------------------------------------------------------- 1 | #include 2 | #define ROUND 60 3 | int main(){ 4 | int min = 1; 5 | while(min > 0){ 6 | printf("please input a min:"); 7 | scanf("%d", &min); 8 | printf("time: %d hours %d min\n", min/60, min%60); 9 | } 10 | return 0; 11 | } -------------------------------------------------------------------------------- /articals/c/Demo/test25.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/suoyuesmile/suo-blog/6068b6934e0bcae9b189fcefdc6a6d3752295a29/articals/c/Demo/test25.exe -------------------------------------------------------------------------------- /articals/c/Demo/test26.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main(){ 3 | int n, max; 4 | printf("please input a intege:"); 5 | scanf("%d", &n); 6 | max = n + 10; 7 | while( n++ < max ){ 8 | printf("%d ", n); 9 | } 10 | return 0; 11 | } -------------------------------------------------------------------------------- /articals/c/Demo/test26.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/suoyuesmile/suo-blog/6068b6934e0bcae9b189fcefdc6a6d3752295a29/articals/c/Demo/test26.exe -------------------------------------------------------------------------------- /articals/c/Demo/test27.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main(){ 3 | int days = 1; 4 | while(days){ 5 | printf("please input days:"); 6 | scanf("%d", &days); 7 | printf("%d days are %d weeks, %d days\n", days, days/7, days%7); 8 | } 9 | return 0; 10 | } -------------------------------------------------------------------------------- /articals/c/Demo/test27.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/suoyuesmile/suo-blog/6068b6934e0bcae9b189fcefdc6a6d3752295a29/articals/c/Demo/test27.exe -------------------------------------------------------------------------------- /articals/c/Demo/test28.c: -------------------------------------------------------------------------------- 1 | #include 2 | #define CM_INCHES 0.393701 3 | #define CM_FEET 0.032808 4 | int main(){ 5 | float height = 1.0; 6 | while(height){ 7 | printf("Enter a height in centimeters:"); 8 | scanf("%f", &height); 9 | printf("%.2f cm = %.0f feet, %.2f inches\n", height, height*CM_FEET, height*CM_INCHES); 10 | } 11 | return 0; 12 | } -------------------------------------------------------------------------------- /articals/c/Demo/test28.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/suoyuesmile/suo-blog/6068b6934e0bcae9b189fcefdc6a6d3752295a29/articals/c/Demo/test28.exe -------------------------------------------------------------------------------- /articals/c/Demo/test29.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main(){ 3 | int n, count = 0, sum = 0; 4 | printf("please input n:"); 5 | scanf("%d" ,&n); 6 | while( count++ < n){ 7 | sum += count; 8 | } 9 | printf("sum = %d\n", sum); 10 | return 0; 11 | } -------------------------------------------------------------------------------- /articals/c/Demo/test29.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/suoyuesmile/suo-blog/6068b6934e0bcae9b189fcefdc6a6d3752295a29/articals/c/Demo/test29.exe -------------------------------------------------------------------------------- /articals/c/Demo/test3.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | void jolly(); 4 | void deny(); 5 | 6 | int main(){ 7 | jolly(); 8 | jolly(); 9 | jolly(); 10 | deny(); 11 | return 0; 12 | } 13 | 14 | void jolly(){ 15 | printf("For he's a jolly good fellow!\n"); 16 | } 17 | void deny(){ 18 | printf("Which nobody can deny!\n"); 19 | } 20 | -------------------------------------------------------------------------------- /articals/c/Demo/test3.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/suoyuesmile/suo-blog/6068b6934e0bcae9b189fcefdc6a6d3752295a29/articals/c/Demo/test3.exe -------------------------------------------------------------------------------- /articals/c/Demo/test30.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main(){ 3 | int n, count = 0, sum = 0; 4 | printf("please input n:"); 5 | scanf("%d" ,&n); 6 | while( count++ < n){ 7 | sum += count * count; 8 | } 9 | printf("sum = %d\n", sum); 10 | return 0; 11 | } -------------------------------------------------------------------------------- /articals/c/Demo/test30.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/suoyuesmile/suo-blog/6068b6934e0bcae9b189fcefdc6a6d3752295a29/articals/c/Demo/test30.exe -------------------------------------------------------------------------------- /articals/c/Demo/test31.c: -------------------------------------------------------------------------------- 1 | #include 2 | void thr(int n); 3 | int main(){ 4 | int n; 5 | scanf("%d", &n); 6 | thr(n); 7 | return 0; 8 | } 9 | 10 | void thr(int n){ 11 | printf("%d\n", n*n*n); 12 | } -------------------------------------------------------------------------------- /articals/c/Demo/test31.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/suoyuesmile/suo-blog/6068b6934e0bcae9b189fcefdc6a6d3752295a29/articals/c/Demo/test31.exe -------------------------------------------------------------------------------- /articals/c/Demo/test32.c: -------------------------------------------------------------------------------- 1 | #include 2 | void resmode(); 3 | int main(){ 4 | int first, second; 5 | printf("start!\n"); 6 | printf("input second operand\n"); 7 | scanf("%d", &second); 8 | printf("input first operand\n"); 9 | scanf("%d", &first); 10 | resmode(first, second); 11 | printf("done!\n"); 12 | } 13 | void resmode(int first, int second){ 14 | printf("%d %% %d is %d\n", first, second, first%second); 15 | } 16 | 17 | -------------------------------------------------------------------------------- /articals/c/Demo/test32.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/suoyuesmile/suo-blog/6068b6934e0bcae9b189fcefdc6a6d3752295a29/articals/c/Demo/test32.exe -------------------------------------------------------------------------------- /articals/c/Demo/test33.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main(){ 3 | char a[27] = "abcdefghijklmnopqrstuvwxyz"; 4 | int i = 0; 5 | while( i++ < 26){ 6 | printf("%c\n", a[i-1]); //前面+1 ,-1即为真实元素 7 | } 8 | return 0; 9 | } -------------------------------------------------------------------------------- /articals/c/Demo/test33.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/suoyuesmile/suo-blog/6068b6934e0bcae9b189fcefdc6a6d3752295a29/articals/c/Demo/test33.exe -------------------------------------------------------------------------------- /articals/c/Demo/test34.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main(){ 3 | int i, j; 4 | char ch = '$'; 5 | for(i = 0; i < 5; ++i){ 6 | for (j = 0; j <= i; ++j) 7 | { 8 | printf("%c", ch); 9 | } 10 | printf("\n"); 11 | } 12 | return 0; 13 | } -------------------------------------------------------------------------------- /articals/c/Demo/test34.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/suoyuesmile/suo-blog/6068b6934e0bcae9b189fcefdc6a6d3752295a29/articals/c/Demo/test34.exe -------------------------------------------------------------------------------- /articals/c/Demo/test35.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main(){ 3 | char lets[27] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; 4 | int i, j; 5 | for (i = 0; i < 6; ++i) 6 | { 7 | for (j = 0; j <= i; j++) 8 | { 9 | printf("%c", lets[5-j]); 10 | } 11 | printf("\n"); 12 | } 13 | return 0; 14 | } -------------------------------------------------------------------------------- /articals/c/Demo/test35.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/suoyuesmile/suo-blog/6068b6934e0bcae9b189fcefdc6a6d3752295a29/articals/c/Demo/test35.exe -------------------------------------------------------------------------------- /articals/c/Demo/test36.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main(){ 3 | char lets[27] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; 4 | int i, j; 5 | for (i = 0; i < 6; i++) 6 | { 7 | for (j = 0; j <= i; j++) 8 | { 9 | printf("%c", lets[i*(i+1)/2+j]); 10 | } 11 | printf("\n"); 12 | } 13 | return 0; 14 | } -------------------------------------------------------------------------------- /articals/c/Demo/test36.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/suoyuesmile/suo-blog/6068b6934e0bcae9b189fcefdc6a6d3752295a29/articals/c/Demo/test36.exe -------------------------------------------------------------------------------- /articals/c/Demo/test37.c: -------------------------------------------------------------------------------- 1 | #include 2 | #define START 64 3 | int main(){ 4 | char ch; 5 | int i, j; 6 | scanf("%c", &ch); 7 | for (j = 0; j < ch - START; ++j) 8 | { 9 | for (i = 0; i < ch - START - j - 1; ++i) 10 | { 11 | printf(" "); 12 | } 13 | for (i = 0; i < j ; ++i) 14 | { 15 | printf("%c", START + 1 + i); 16 | } 17 | printf("%c", START + j + 1); 18 | for (i = j; i > 0; --i) 19 | { 20 | printf("%c", START + i); 21 | } 22 | printf("\n"); 23 | } 24 | return 0; 25 | } -------------------------------------------------------------------------------- /articals/c/Demo/test37.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/suoyuesmile/suo-blog/6068b6934e0bcae9b189fcefdc6a6d3752295a29/articals/c/Demo/test37.exe -------------------------------------------------------------------------------- /articals/c/Demo/test38.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main(){ 3 | int i, start, end; 4 | printf("start,end\n"); 5 | scanf("%d,%d",&start, &end); 6 | for (i = start; i <= end; ++i) 7 | { 8 | printf("------------------------------\n"); 9 | printf("|%-9d|%-9d|%-9d|\n", i, i*i, i*i*i); 10 | } 11 | printf("------------------------------\n"); 12 | return 0; 13 | } -------------------------------------------------------------------------------- /articals/c/Demo/test38.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/suoyuesmile/suo-blog/6068b6934e0bcae9b189fcefdc6a6d3752295a29/articals/c/Demo/test38.exe -------------------------------------------------------------------------------- /articals/c/Demo/test39.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | int main(){ 4 | char w[50]; 5 | scanf("%s", w); 6 | int len = strlen(w); 7 | while(len-- >= 0){ 8 | printf("%c", w[len]); 9 | } 10 | return 0; 11 | } -------------------------------------------------------------------------------- /articals/c/Demo/test39.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/suoyuesmile/suo-blog/6068b6934e0bcae9b189fcefdc6a6d3752295a29/articals/c/Demo/test39.exe -------------------------------------------------------------------------------- /articals/c/Demo/test4.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | void br(); 4 | void ic(); 5 | 6 | int main(){ 7 | br(); 8 | printf(", "); 9 | ic(); 10 | printf("\n"); 11 | ic(); 12 | printf(",\n"); 13 | br(); 14 | return 0; 15 | } 16 | void br(){ 17 | printf("Brazil, Russia"); 18 | } 19 | void ic(){ 20 | printf("India, China"); 21 | } 22 | -------------------------------------------------------------------------------- /articals/c/Demo/test4.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/suoyuesmile/suo-blog/6068b6934e0bcae9b189fcefdc6a6d3752295a29/articals/c/Demo/test4.exe -------------------------------------------------------------------------------- /articals/c/Demo/test40.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main(){ 3 | float num1, num2; 4 | while (scanf("%f%f", &num1, &num2) != 2){ 5 | printf("please input correct digit!\n"); 6 | } 7 | printf("%f\n", (num1-num2)/(num1*num2)); 8 | return 0; 9 | } 10 | //?????????????????????????????????? -------------------------------------------------------------------------------- /articals/c/Demo/test40.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/suoyuesmile/suo-blog/6068b6934e0bcae9b189fcefdc6a6d3752295a29/articals/c/Demo/test40.exe -------------------------------------------------------------------------------- /articals/c/Demo/test41.c: -------------------------------------------------------------------------------- 1 | #include 2 | float addff(float f1, float f2); 3 | int main(){ 4 | float num1, num2; 5 | while ( scanf("%f%f", &num1, &num2) != 2 ){ 6 | printf("please input correct digit!\n"); 7 | } 8 | printf("%f\n", addff(num1, num2)); 9 | return 0; 10 | } 11 | float addff(float f1, float f2){ 12 | return (f1-f2)/(f1*f2); 13 | } -------------------------------------------------------------------------------- /articals/c/Demo/test41.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/suoyuesmile/suo-blog/6068b6934e0bcae9b189fcefdc6a6d3752295a29/articals/c/Demo/test41.exe -------------------------------------------------------------------------------- /articals/c/Demo/test42.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main(){ 3 | int a, b; 4 | printf("Enter lower and upper integer limits:"); 5 | scanf("%d%d", &a, &b); 6 | while( a < b ){ 7 | printf("The sums of the squares from %d to %d is %d\n", a*a, b*b, a*a+b*b); 8 | printf("Enter next set of limits:"); 9 | scanf("%d%d", &a, &b); 10 | } 11 | printf("done!\n"); 12 | return 0; 13 | } -------------------------------------------------------------------------------- /articals/c/Demo/test42.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/suoyuesmile/suo-blog/6068b6934e0bcae9b189fcefdc6a6d3752295a29/articals/c/Demo/test42.exe -------------------------------------------------------------------------------- /articals/c/Demo/test43.c: -------------------------------------------------------------------------------- 1 | #include 2 | #define LEN 8 3 | void swap(int *a, int *b); 4 | int main() 5 | { 6 | int i, j, a[LEN]; 7 | for (i = 0; i < LEN; ++i) 8 | { 9 | scanf("%d", &a[i]); 10 | } 11 | for (i = 0; i < LEN -1; ++i) 12 | { 13 | for (j = 0; j < LEN - i - 1; ++j) 14 | { 15 | if(a[j] < a[j+1]) 16 | { 17 | swap(&a[j], &a[j+1]); 18 | } 19 | } 20 | } 21 | for (i = 0; i < LEN; ++i) 22 | { 23 | printf("%d ", a[i]); 24 | } 25 | } 26 | void swap(int *a, int *b) 27 | { 28 | int t = *a; 29 | *a = *b; 30 | *b = t; 31 | } -------------------------------------------------------------------------------- /articals/c/Demo/test43.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/suoyuesmile/suo-blog/6068b6934e0bcae9b189fcefdc6a6d3752295a29/articals/c/Demo/test43.exe -------------------------------------------------------------------------------- /articals/c/Demo/test44.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main(){ 3 | float f1 = 1.0, f2 = 1.0, sum1 = 0, sum2 = 0; 4 | int i, n; 5 | scanf("%d", &n); 6 | while( n > 0){ 7 | f1 = 1.0, f2 = 1.0, sum1 = 0, sum2 = 0; 8 | for (i = 0; i < n; ++i) 9 | { 10 | sum1 += f1/f2; 11 | if( (i+1)%2 == 0 ) { 12 | sum2 -= f1/f2; 13 | }else{ 14 | sum2 += f1/f2; 15 | } 16 | f2++; 17 | } 18 | printf("sum1 = %f, sum2 = %f\n", sum1, sum2); 19 | scanf("%d", &n); 20 | } 21 | return 0; 22 | } -------------------------------------------------------------------------------- /articals/c/Demo/test44.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/suoyuesmile/suo-blog/6068b6934e0bcae9b189fcefdc6a6d3752295a29/articals/c/Demo/test44.exe -------------------------------------------------------------------------------- /articals/c/Demo/test45.c: -------------------------------------------------------------------------------- 1 | #include 2 | #define LEN 8 3 | int main(){ 4 | int arr[LEN]; 5 | int i, tem = 1; 6 | for (i = 0; i < LEN; ++i) 7 | { 8 | tem *= 2; 9 | arr[i] = tem; 10 | } 11 | i = 0; 12 | do{ 13 | printf("%d ", arr[i]); 14 | i++; 15 | }while (i < LEN); 16 | return 0; 17 | } -------------------------------------------------------------------------------- /articals/c/Demo/test45.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/suoyuesmile/suo-blog/6068b6934e0bcae9b189fcefdc6a6d3752295a29/articals/c/Demo/test45.exe -------------------------------------------------------------------------------- /articals/c/Demo/test46.c: -------------------------------------------------------------------------------- 1 | #include 2 | #define LEN 8 3 | int main(){ 4 | double a[LEN], b[LEN], tem = 0; 5 | int i; 6 | for (i = 0; i < LEN; ++i) 7 | { 8 | printf("Enter a double is NO%d:", i+1); 9 | scanf("%lf", &a[i]); 10 | tem += a[i]; 11 | b[i] = tem; //灵活使用临时变量 12 | } 13 | i = 0; 14 | while(i++ < LEN) 15 | { 16 | printf("%.2lf ", a[i-1]); 17 | } 18 | i = 0; 19 | printf("\n"); 20 | while(i++ < LEN) 21 | { 22 | printf("%.2lf ", b[i-1]); 23 | } 24 | printf("\n"); 25 | return 0; 26 | } -------------------------------------------------------------------------------- /articals/c/Demo/test46.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/suoyuesmile/suo-blog/6068b6934e0bcae9b189fcefdc6a6d3752295a29/articals/c/Demo/test46.exe -------------------------------------------------------------------------------- /articals/c/Demo/test47.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #define MAX_LEN 255 4 | int main(){ 5 | char a[MAX_LEN]; 6 | scanf("%s", a); 7 | int len = strlen(a); 8 | while(len-- > 0){ 9 | printf("%c", a[len]); 10 | } 11 | return 0; 12 | } -------------------------------------------------------------------------------- /articals/c/Demo/test47.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/suoyuesmile/suo-blog/6068b6934e0bcae9b189fcefdc6a6d3752295a29/articals/c/Demo/test47.exe -------------------------------------------------------------------------------- /articals/c/Demo/test48.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main(){ 3 | int start = 5, week, weekfds, i = 0; 4 | printf("start friends is %d\n", start); 5 | scanf("%d", &week); 6 | while(i++ < week){ 7 | weekfds= (start-i) * 2; 8 | printf("week%d friends is %d\n", i, weekfds); 9 | start = weekfds; 10 | } 11 | return 0; 12 | } -------------------------------------------------------------------------------- /articals/c/Demo/test48.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/suoyuesmile/suo-blog/6068b6934e0bcae9b189fcefdc6a6d3752295a29/articals/c/Demo/test48.exe -------------------------------------------------------------------------------- /articals/c/Demo/test49.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | int main(){ 4 | char ch; 5 | int nblank = 0, nt = 0, n = 0; 6 | while( (ch = getchar()) != '#' ){ 7 | if(ch == '\n') 8 | nt++; 9 | else if(isblank(ch)) 10 | nblank++; 11 | else 12 | n++; 13 | } 14 | printf("nblank = %d, nt = %d, n = %d\n", nblank, nt, n); 15 | return 0; 16 | } -------------------------------------------------------------------------------- /articals/c/Demo/test49.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/suoyuesmile/suo-blog/6068b6934e0bcae9b189fcefdc6a6d3752295a29/articals/c/Demo/test49.exe -------------------------------------------------------------------------------- /articals/c/Demo/test5.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main(){ 3 | int toes = 10; 4 | printf("toes*2 = %d, toes^2 = %d\n", toes * 2, toes * toes); 5 | return 0; 6 | } -------------------------------------------------------------------------------- /articals/c/Demo/test5.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/suoyuesmile/suo-blog/6068b6934e0bcae9b189fcefdc6a6d3752295a29/articals/c/Demo/test5.exe -------------------------------------------------------------------------------- /articals/c/Demo/test50.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main(){ 3 | char ch; 4 | int n = 0; 5 | while( (ch = getchar()) != '#' ){ 6 | putchar(ch); 7 | printf(" %d ", ch); 8 | n++; 9 | if(n % 8 == 0){ 10 | putchar('\n'); 11 | } 12 | } 13 | return 0; 14 | } -------------------------------------------------------------------------------- /articals/c/Demo/test50.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/suoyuesmile/suo-blog/6068b6934e0bcae9b189fcefdc6a6d3752295a29/articals/c/Demo/test50.exe -------------------------------------------------------------------------------- /articals/c/Demo/test51.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main(){ 3 | char ch, pre; 4 | int n = 0; 5 | while( (ch = getchar()) != '#' ){ 6 | if(pre == 'e' && ch == 'i') 7 | n++; 8 | pre = ch; 9 | } 10 | printf("%d\n", n); 11 | return 0; 12 | } 13 | 14 | -------------------------------------------------------------------------------- /articals/c/Demo/test51.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/suoyuesmile/suo-blog/6068b6934e0bcae9b189fcefdc6a6d3752295a29/articals/c/Demo/test51.exe -------------------------------------------------------------------------------- /articals/c/Demo/test52.c: -------------------------------------------------------------------------------- 1 | #include 2 | #define BASIC_SALARY 10.00 3 | #define LOVER_RATE 0.15 4 | #define MIDDLE_RATE 0.2 5 | #define HIGH_RATE 0.25 6 | 7 | int main(){ 8 | float work_hours, salary, tax, income; 9 | printf("Enter your work hours:"); 10 | scanf("%f", &work_hours); 11 | if(work_hours > 40){ 12 | work_hours= 40 + (work_hours-40) * 1.5; 13 | } 14 | salary = work_hours * BASIC_SALARY; 15 | if(salary <= 300) 16 | tax = salary * LOVER_RATE; 17 | else if(salary <= 450) 18 | tax = 300 * LOVER_RATE + (salary-300) * MIDDLE_RATE; 19 | else 20 | tax = 300 * LOVER_RATE + 150 * MIDDLE_RATE + (salary-450) * HIGH_RATE ; 21 | income = salary - tax; 22 | printf("his salary, tax, income are %.2f, %.2f, %.2f\n", salary, tax, income); 23 | return 0; 24 | } -------------------------------------------------------------------------------- /articals/c/Demo/test52.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/suoyuesmile/suo-blog/6068b6934e0bcae9b189fcefdc6a6d3752295a29/articals/c/Demo/test52.exe -------------------------------------------------------------------------------- /articals/c/Demo/test53.c: -------------------------------------------------------------------------------- 1 | #include 2 | #define LOVER_RATE 0.15 3 | #define MIDDLE_RATE 0.2 4 | #define HIGH_RATE 0.25 5 | 6 | int main(){ 7 | float work_hours, basic, salary, tax, income; 8 | int choice; 9 | printf("Enter your work hours:"); 10 | scanf("%f", &work_hours); 11 | printf("*******************************************************************\n"); 12 | printf("Enter the number corresponding to the desired pay rate or action:\n"); 13 | printf("1) $8.75/hr"); 14 | printf("\t\t\t2) $9.33/hr\n"); 15 | printf("3) $10.00/hr"); 16 | printf("\t\t\t4) $11.2/hr\n"); 17 | printf("5) quit!\n"); 18 | printf("*******************************************************************\n"); 19 | while ( scanf("%d", &choice) == 1){ 20 | switch (choice){ 21 | case 1: basic = 8.75; break; 22 | case 2: basic = 9.33; break; 23 | case 3: basic = 10.00; break; 24 | case 4: basic = 11.2; break; 25 | default: break; 26 | } 27 | } 28 | if(work_hours > 40){ 29 | work_hours= 40 + (work_hours-40) * 1.5; 30 | } 31 | salary = work_hours * basic; 32 | if(salary <= 300) 33 | tax = salary * LOVER_RATE; 34 | else if(salary <= 450) 35 | tax = 300 * LOVER_RATE + (salary-300) * MIDDLE_RATE; 36 | else 37 | tax = 300 * LOVER_RATE + 150 * MIDDLE_RATE + (salary-450) * HIGH_RATE ; 38 | income = salary - tax; 39 | printf("his salary, tax, income are %.2f, %.2f, %.2f\n", salary, tax, income); 40 | return 0; 41 | } 42 | -------------------------------------------------------------------------------- /articals/c/Demo/test53.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/suoyuesmile/suo-blog/6068b6934e0bcae9b189fcefdc6a6d3752295a29/articals/c/Demo/test53.exe -------------------------------------------------------------------------------- /articals/c/Demo/test54.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | _Bool isPrime(int n); 5 | int main(){ 6 | unsigned a, i; 7 | printf("Enter a integer n(n>0):"); 8 | if ( scanf("%u", &a) != 1 ) //not match but return 1 9 | printf("enter a integer must more than 0"); 10 | else 11 | for (i = 2; i <= a; ++i) 12 | if(isPrime(i)) 13 | printf("%d ", i); 14 | printf("\n"); 15 | return 0; 16 | } 17 | _Bool isPrime(int n){ 18 | _Bool res = 1; 19 | int i, j; 20 | for (i = 1; i <= sqrt(n); ++i) 21 | for (j = sqrt(n); j < n; ++j) 22 | if(i * j == n) 23 | res = 0; 24 | return res; 25 | } -------------------------------------------------------------------------------- /articals/c/Demo/test54.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/suoyuesmile/suo-blog/6068b6934e0bcae9b189fcefdc6a6d3752295a29/articals/c/Demo/test54.exe -------------------------------------------------------------------------------- /articals/c/Demo/test55.c: -------------------------------------------------------------------------------- 1 | #include 2 | #define NORMAL_TAX 0.15 3 | #define EXT_TAX 0.28 4 | void menu(); 5 | int main(){ 6 | int choice; 7 | float salary, ext_line, tax; 8 | printf("enter your salary:\n"); 9 | scanf("%f", &salary); 10 | menu(); 11 | while( scanf("%d", &choice) == 1){ 12 | switch (choice){ 13 | case 1: ext_line = 17850;break; 14 | case 2: ext_line = 23900;break; 15 | case 3: ext_line = 29750;break; 16 | case 4: ext_line = 14875;break; 17 | default: printf("bye\n");break; 18 | } 19 | tax = ( salary <= ext_line ? salary*NORMAL_TAX : ext_line*NORMAL_TAX + (salary-ext_line)*EXT_TAX ); 20 | printf("%.2f\n", tax); 21 | } 22 | 23 | return 0; 24 | } 25 | void menu(){ 26 | printf("enter a status choice:"); 27 | printf("**********status************\n"); 28 | printf(" 1) single\n"); 29 | printf(" 2) host\n"); 30 | printf(" 3) married\n"); 31 | printf(" 4) divorce\n"); 32 | printf(" 5) input 'q' eixt\n"); 33 | printf("****************************\n"); 34 | } -------------------------------------------------------------------------------- /articals/c/Demo/test55.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/suoyuesmile/suo-blog/6068b6934e0bcae9b189fcefdc6a6d3752295a29/articals/c/Demo/test55.exe -------------------------------------------------------------------------------- /articals/c/Demo/test56.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/suoyuesmile/suo-blog/6068b6934e0bcae9b189fcefdc6a6d3752295a29/articals/c/Demo/test56.exe -------------------------------------------------------------------------------- /articals/c/Demo/test57.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | int main(){ 4 | char ch; 5 | int count = 0; 6 | while( (ch = getchar()) != EOF ) 7 | { 8 | if(isblank(ch) || ch == '\n') 9 | continue; 10 | count++; 11 | } 12 | printf("count : %d\n", count); 13 | return 0; 14 | } -------------------------------------------------------------------------------- /articals/c/Demo/test57.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/suoyuesmile/suo-blog/6068b6934e0bcae9b189fcefdc6a6d3752295a29/articals/c/Demo/test57.exe -------------------------------------------------------------------------------- /articals/c/Demo/test58.c: -------------------------------------------------------------------------------- 1 | #include 2 | void dealSpecial(char sp); 3 | int main(){ 4 | char ch; 5 | while( (ch = getchar()) != EOF ){ 6 | // if( ch == '\n' ) 7 | // continue; 8 | dealSpecial(ch); 9 | // putchar(ch); 10 | // while(getchar() != '\n') 11 | // continue; 12 | } 13 | return 0; 14 | } 15 | void dealSpecial(char sp){ 16 | switch (sp){ 17 | case '\n': printf("\\n %d", sp); break; 18 | case '\t': printf("\\t %d", sp); break; 19 | case ' ': printf("\\ %d", sp); break; 20 | } 21 | } -------------------------------------------------------------------------------- /articals/c/Demo/test58.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/suoyuesmile/suo-blog/6068b6934e0bcae9b189fcefdc6a6d3752295a29/articals/c/Demo/test58.exe -------------------------------------------------------------------------------- /articals/c/Demo/test59.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | int main(){ 4 | char ch; 5 | int lower = 0, upper = 0; 6 | while( (ch = getchar()) != EOF ){ 7 | if( ch == '\n' ) 8 | continue; 9 | if(islower(ch)) 10 | lower++; 11 | if(isupper(ch)) 12 | upper++; 13 | } 14 | printf("lower= %d, upper= %d\n", lower, upper); 15 | return 0; 16 | } -------------------------------------------------------------------------------- /articals/c/Demo/test59.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/suoyuesmile/suo-blog/6068b6934e0bcae9b189fcefdc6a6d3752295a29/articals/c/Demo/test59.exe -------------------------------------------------------------------------------- /articals/c/Demo/test6.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main(){ 3 | int age = 23; 4 | printf("my day in life:%d\n", age*365); 5 | return 0; 6 | } -------------------------------------------------------------------------------- /articals/c/Demo/test6.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/suoyuesmile/suo-blog/6068b6934e0bcae9b189fcefdc6a6d3752295a29/articals/c/Demo/test6.exe -------------------------------------------------------------------------------- /articals/c/Demo/test60.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main(){ 3 | char ch; 4 | int count = 0; 5 | while( (ch = getchar()) != EOF ){ 6 | count++; 7 | if(ch == ' ' || ch == '\n'){ 8 | printf("%d ", count - 1); 9 | count = 0; 10 | } 11 | } 12 | return 0; 13 | } -------------------------------------------------------------------------------- /articals/c/Demo/test60.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/suoyuesmile/suo-blog/6068b6934e0bcae9b189fcefdc6a6d3752295a29/articals/c/Demo/test60.exe -------------------------------------------------------------------------------- /articals/c/Demo/test61.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main(){ 3 | int ran, lower = 1, upper = 100, i = 0; 4 | int smart = (lower + upper) / 2; 5 | printf("please enter 1 ~ 100 a integer:"); 6 | scanf("%d", &ran); 7 | while( ran != smart){ 8 | if(ran < smart) 9 | upper = smart; 10 | else 11 | lower = smart; 12 | i++; 13 | printf("though %d times = %d\n", i, smart); 14 | smart = (lower + upper) / 2; 15 | } 16 | printf("though %d times = %d\n", i+1, smart); 17 | return 0; 18 | } -------------------------------------------------------------------------------- /articals/c/Demo/test61.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/suoyuesmile/suo-blog/6068b6934e0bcae9b189fcefdc6a6d3752295a29/articals/c/Demo/test61.exe -------------------------------------------------------------------------------- /articals/c/Demo/test62.c: -------------------------------------------------------------------------------- 1 | #include 2 | void count(); 3 | int get_int(); 4 | char get_first(); 5 | char get_choice(); 6 | int main(){ 7 | char choice; 8 | count(); 9 | while( (choice = get_choice()) != 'q' ){ 10 | switch (choice){ 11 | case 'a': 12 | printf("buy low, sell high\n"); 13 | break; 14 | case 'b': 15 | printf("\a\n"); 16 | break; 17 | case 'c': 18 | count(); 19 | break; 20 | default: 21 | printf("error!!!\n"); 22 | break; 23 | } 24 | } 25 | return 0; 26 | } 27 | //计数 28 | void count(){ 29 | int n, i; 30 | printf("Count how far?\n"); 31 | n = get_int(); 32 | for (int i = 0; i <= n; ++i) 33 | { 34 | printf("%d\n", i); 35 | } 36 | while( getchar() != '\n' ) 37 | continue; 38 | } 39 | //异常处理 40 | int get_int(){ 41 | int n; 42 | char ch; 43 | while( scanf("%d", &n) != 1 ){ 44 | while( getchar() != '\n') 45 | putchar(ch); 46 | printf("is not a integer!!!\n"); 47 | } 48 | return n; 49 | } 50 | //过滤换行符 51 | char get_first(){ 52 | char choice; 53 | choice = getchar(); 54 | while( getchar() != '\n' ) 55 | continue; 56 | return choice; 57 | } 58 | //删选合适的字符 59 | char get_choice(){ 60 | char choice; 61 | printf("please enter a, b, c\n"); 62 | choice = get_first(); 63 | while( (choice < 'a' || choice > 'c') && choice != 'q'){ 64 | printf("please enter correct code!!\n"); 65 | choice = get_first(); 66 | } 67 | return choice; 68 | } 69 | -------------------------------------------------------------------------------- /articals/c/Demo/test62.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/suoyuesmile/suo-blog/6068b6934e0bcae9b189fcefdc6a6d3752295a29/articals/c/Demo/test62.exe -------------------------------------------------------------------------------- /articals/c/Demo/test63.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main(){ 3 | 4 | return 0; 5 | } -------------------------------------------------------------------------------- /articals/c/Demo/test64.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main(){ 3 | 4 | return 0; 5 | } -------------------------------------------------------------------------------- /articals/c/Demo/test65.c: -------------------------------------------------------------------------------- 1 | #include 2 | void show(char, int, int); 3 | int main(void){ 4 | char a; 5 | int b, c; 6 | scanf("%c%d%d", &a, &b, &c); 7 | show(a, b ,c); 8 | return 0; 9 | } 10 | void show(char a, int b, int c) { 11 | int i, j; 12 | for (int i = 0; i < c; ++i) 13 | { 14 | for (int j = 0; j < b; ++j) 15 | { 16 | putchar(a); 17 | } 18 | putchar('\n'); 19 | } 20 | } -------------------------------------------------------------------------------- /articals/c/Demo/test65.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/suoyuesmile/suo-blog/6068b6934e0bcae9b189fcefdc6a6d3752295a29/articals/c/Demo/test65.exe -------------------------------------------------------------------------------- /articals/c/Demo/test66.c: -------------------------------------------------------------------------------- 1 | #include 2 | double avg(double, double); 3 | int main(){ 4 | double a, b; 5 | scanf("%lf%lf", &a, &b); 6 | printf("%.2lf", avg(a, b) ); 7 | return 0; 8 | } 9 | double avg(double a, double b){ 10 | return 1./( (1./a + 1./b)/2. ); 11 | } -------------------------------------------------------------------------------- /articals/c/Demo/test66.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/suoyuesmile/suo-blog/6068b6934e0bcae9b189fcefdc6a6d3752295a29/articals/c/Demo/test66.exe -------------------------------------------------------------------------------- /articals/c/Demo/test67.c: -------------------------------------------------------------------------------- 1 | #include 2 | void large_of(double *, double *); 3 | int main(void){ 4 | double a, b; 5 | scanf("%lf%lf", &a, &b); 6 | large_of(&a, &b); 7 | printf("%.2lf, %.2lf\n", a, b); 8 | return 0; 9 | } 10 | void large_of(double *a, double *b){ 11 | // *a > *b ? *b = *a : *a = *b ; ?????? 12 | if( *a > *b ) 13 | *b = *a; 14 | else 15 | *a = *b; 16 | } 17 | -------------------------------------------------------------------------------- /articals/c/Demo/test67.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/suoyuesmile/suo-blog/6068b6934e0bcae9b189fcefdc6a6d3752295a29/articals/c/Demo/test67.exe -------------------------------------------------------------------------------- /articals/c/Demo/test68.c: -------------------------------------------------------------------------------- 1 | #include 2 | void order(double *, double *, double *); 3 | void swap(double *, double *); 4 | int main(void){ 5 | double a, b, c; 6 | scanf("%lf%lf%lf", &a, &b, &c); 7 | order(&a, &b, &c); 8 | printf("%.2lf, %.2lf, %.2lf\n", a, b, c); 9 | return 0; 10 | } 11 | void order(double *a, double *b, double *c){ 12 | if(*a > *b) 13 | swap(a, b); 14 | if(*b > *c) 15 | swap(b, c); 16 | } 17 | void swap(double *m, double *n){ 18 | double tem; 19 | tem = *m; 20 | *m = *n; 21 | *n = tem; 22 | } -------------------------------------------------------------------------------- /articals/c/Demo/test68.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/suoyuesmile/suo-blog/6068b6934e0bcae9b189fcefdc6a6d3752295a29/articals/c/Demo/test68.exe -------------------------------------------------------------------------------- /articals/c/Demo/test69.c: -------------------------------------------------------------------------------- 1 | #include 2 | double power(double, int); 3 | int main(){ 4 | double n; 5 | int c; 6 | scanf("%lf%d", &n, &c); 7 | printf("%.2lf\n", power(n, c)); 8 | return 0; 9 | } 10 | double power(double n, int c){ 11 | int i, pow = 1; 12 | if( n == 0 ) 13 | return 0; 14 | if( c == 0 ) 15 | return 1; 16 | for (i = 1; i <= c; ++i) 17 | pow *= n; 18 | return pow; 19 | } 20 | -------------------------------------------------------------------------------- /articals/c/Demo/test69.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/suoyuesmile/suo-blog/6068b6934e0bcae9b189fcefdc6a6d3752295a29/articals/c/Demo/test69.exe -------------------------------------------------------------------------------- /articals/c/Demo/test7.c: -------------------------------------------------------------------------------- 1 | #include 2 | void smile(); 3 | int main(){ 4 | int i, j; 5 | for(i = 3; i > 0; i--) 6 | { 7 | for(j = i; j > 0; j--) 8 | smile(); 9 | printf("\n"); 10 | } 11 | return 0; 12 | } 13 | void smile(){ 14 | printf("Smile!"); 15 | } -------------------------------------------------------------------------------- /articals/c/Demo/test7.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/suoyuesmile/suo-blog/6068b6934e0bcae9b189fcefdc6a6d3752295a29/articals/c/Demo/test7.exe -------------------------------------------------------------------------------- /articals/c/Demo/test70.c: -------------------------------------------------------------------------------- 1 | #include 2 | double power(double, int); 3 | int main(){ 4 | double n; 5 | int c; 6 | scanf("%lf%d", &n, &c); 7 | printf("%.2lf\n", power(n, c)); 8 | return 0; 9 | } 10 | double power(double n, int c){ 11 | if( n == 0 ) 12 | return 0; 13 | if( c == 0 ) 14 | return 1; 15 | return n*power(n, c-1); 16 | } -------------------------------------------------------------------------------- /articals/c/Demo/test70.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/suoyuesmile/suo-blog/6068b6934e0bcae9b189fcefdc6a6d3752295a29/articals/c/Demo/test70.exe -------------------------------------------------------------------------------- /articals/c/Demo/test71.c: -------------------------------------------------------------------------------- 1 | #include 2 | void to_base_n(int, int); 3 | int main(void){ 4 | int x, n; 5 | scanf("%d%d", &x, &n); 6 | to_base_n(x, n); 7 | return 0; 8 | } 9 | void to_base_n(int x, int n){ 10 | int r; 11 | r = x%n; 12 | if(x >= n) 13 | to_base_n(x/n, n); 14 | printf("%d", r ); 15 | } -------------------------------------------------------------------------------- /articals/c/Demo/test71.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/suoyuesmile/suo-blog/6068b6934e0bcae9b189fcefdc6a6d3752295a29/articals/c/Demo/test71.exe -------------------------------------------------------------------------------- /articals/c/Demo/test72.c: -------------------------------------------------------------------------------- 1 | #include 2 | int fibonacciRec(int); //递归 3 | int fibonacci(int); //非递归 4 | int main(void){ 5 | int n; 6 | scanf("%d", &n); 7 | printf("%d\n", fibonacciRec(n) ); 8 | printf("%d\n", fibonacci(n) ); 9 | return 0; 10 | } 11 | int fibonacciRec(int n){ 12 | if(n == 1 || n == 2) 13 | return 1; 14 | else 15 | return fibonacciRec(n-1) + fibonacciRec(n-2); 16 | } 17 | int fibonacci(int n){ 18 | int i, fib1 = 1, fib2 = 1; 19 | if( n == 1 || n == 2) 20 | return 1; 21 | for(i = 3 ; i <= n; i++){ 22 | fib2 = fib1 + fib2; 23 | fib1 = fib2 - fib1; 24 | } 25 | return fib2; 26 | } -------------------------------------------------------------------------------- /articals/c/Demo/test72.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/suoyuesmile/suo-blog/6068b6934e0bcae9b189fcefdc6a6d3752295a29/articals/c/Demo/test72.exe -------------------------------------------------------------------------------- /articals/c/Demo/test73.c: -------------------------------------------------------------------------------- 1 | #include 2 | #define N 5 3 | void cp_arr(double [], const double [], int); 4 | void cp_ptr(double [], const double *, int); 5 | void cp_ptrs(double *, const double *, const double *); 6 | void show_arr(double [], int); 7 | int main(void){ 8 | double source[N] = {1, 2, 3, 4, 5}; 9 | double target1[N], target2[N], target3[N]; 10 | cp_arr(target1, source, N); 11 | cp_ptr(target2, source, N); 12 | cp_ptrs(target3, source, source+N); 13 | show_arr(target1, N); 14 | putchar('\n'); 15 | show_arr(target2, N); 16 | putchar('\n'); 17 | show_arr(target3, N); 18 | putchar('\n'); 19 | return 0; 20 | } 21 | void cp_arr(double target[], const double source[], int n){ 22 | int i; 23 | for (i = 0; i < n; ++i) 24 | { 25 | target[i] = source[i]; 26 | } 27 | } 28 | void cp_ptr(double target[], const double *source, int n){ 29 | int i; 30 | for (i = 0; i < n; ++i) 31 | { 32 | target[i] = *(source+i); 33 | } 34 | } 35 | void cp_ptrs(double target[], const double *source_start, const double *source_end){ 36 | while(source_start < source_end){ 37 | *target = *source_start++; 38 | target++; 39 | } 40 | } 41 | void show_arr(double a[], int n){ 42 | int i; 43 | for (i = 0; i < n; ++i) 44 | { 45 | printf("%.2lf ", a[i]); 46 | } 47 | } -------------------------------------------------------------------------------- /articals/c/Demo/test73.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/suoyuesmile/suo-blog/6068b6934e0bcae9b189fcefdc6a6d3752295a29/articals/c/Demo/test73.exe -------------------------------------------------------------------------------- /articals/c/Demo/test74.c: -------------------------------------------------------------------------------- 1 | #include 2 | #define SIZE 10 3 | void sort(double [], int); 4 | void swap(double *, double *); 5 | void show_arr(const double [], int); 6 | int main(void){ 7 | double a[] = {2,4,6,7,8,3,5,1,10,9}; 8 | sort(a, SIZE); 9 | show_arr(a, SIZE); 10 | return 0; 11 | } 12 | void sort(double a[], int n){ 13 | int i, j; 14 | for (int i = 0; i < n; ++i) 15 | for (int j = 0; j < n - i; ++j) 16 | if(a[j+1] > a[j]) 17 | swap(&a[j+1], &a[j]); 18 | } 19 | void swap(double *p, double *q){ 20 | double temp = *p; 21 | *p = *q; 22 | *q = temp; 23 | } 24 | void show_arr(const double a[], int n){ 25 | int i; 26 | for (i = 0; i < n; ++i) 27 | { 28 | printf("%.2lf ", a[i]); 29 | } 30 | } -------------------------------------------------------------------------------- /articals/c/Demo/test74.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/suoyuesmile/suo-blog/6068b6934e0bcae9b189fcefdc6a6d3752295a29/articals/c/Demo/test74.exe -------------------------------------------------------------------------------- /articals/c/Demo/test75.c: -------------------------------------------------------------------------------- 1 | #include 2 | #define COLS 3 3 | #define ROWS 2 4 | void cp_arr(double [], const double [], int); 5 | void cp2_arr2(double [][COLS], const double [][COLS], int); 6 | void show_arr2(const double [][COLS], int); 7 | 8 | int main(void){ 9 | double arr1[ROWS][COLS] = { {1,2,3}, {4,5,6} }; 10 | double arr2[ROWS][COLS]; 11 | cp2_arr2(arr2, arr1, ROWS); 12 | show_arr2(arr2, ROWS); 13 | return 0; 14 | } 15 | void cp_arr(double target[], const double source[], int n){ 16 | int i; 17 | for (i = 0; i < n; ++i) 18 | { 19 | target[i] = source[i]; 20 | } 21 | } 22 | void cp2_arr2(double tgt[][COLS], const double src[][COLS], int rows){ 23 | int i; 24 | for (i = 0; i < rows; ++i) 25 | cp_arr(tgt[i], src[i], COLS); 26 | } 27 | void show_arr2(const double a[][COLS], int rows){ 28 | int i, j; 29 | for (i = 0; i < rows; ++i) 30 | { 31 | for (j = 0; j < COLS; ++j) 32 | printf("%.2lf ", a[i][j]); 33 | printf("\n"); 34 | } 35 | } -------------------------------------------------------------------------------- /articals/c/Demo/test75.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/suoyuesmile/suo-blog/6068b6934e0bcae9b189fcefdc6a6d3752295a29/articals/c/Demo/test75.exe -------------------------------------------------------------------------------- /articals/c/Demo/test76.c: -------------------------------------------------------------------------------- 1 | #include 2 | #define N 7 3 | #define M 3 4 | void cp_arr(double [], const double [], int); 5 | void cp_ptr(double [], const double *, int); 6 | void cp_ptrs(double *, const double *, const double *); 7 | void show_arr(double [], int); 8 | int main(void){ 9 | double source[N] = {1, 2, 3, 4, 5, 6, 7}; 10 | double target1[M], target2[M], target3[M]; 11 | cp_arr(target1, source, M); 12 | cp_ptr(target2, source, M); 13 | cp_ptrs(target3, source+2, source+5); 14 | show_arr(target1, M); 15 | putchar('\n'); 16 | show_arr(target2, M); 17 | putchar('\n'); 18 | show_arr(target3, M); 19 | putchar('\n'); 20 | return 0; 21 | } 22 | void cp_arr(double target[], const double source[], int m){ 23 | int i; 24 | for (i = 2; i < 2+m; ++i) 25 | { 26 | target[i-2] = source[i]; 27 | } 28 | } 29 | void cp_ptr(double target[], const double *source, int m){ 30 | int i; 31 | for (i = 2; i < 2+m; ++i) 32 | { 33 | target[i-2] = *(source+i); 34 | } 35 | } 36 | void cp_ptrs(double target[], const double *source_start, const double *source_end){ 37 | while(source_start < source_end){ 38 | *target = *source_start++; 39 | target++; 40 | } 41 | } 42 | void show_arr(double a[], int n){ 43 | int i; 44 | for (i = 0; i < n; ++i) 45 | { 46 | printf("%.2lf ", a[i]); 47 | } 48 | } -------------------------------------------------------------------------------- /articals/c/Demo/test76.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/suoyuesmile/suo-blog/6068b6934e0bcae9b189fcefdc6a6d3752295a29/articals/c/Demo/test76.exe -------------------------------------------------------------------------------- /articals/c/Demo/test77.c: -------------------------------------------------------------------------------- 1 | #include 2 | void show_vla(int, int, double [*][*]); 3 | int main(void){ 4 | int i, j; 5 | const int rows = 3; 6 | const int cols = 5; 7 | double arr[rows][cols] = {{1,2,3,4,5}, {6,7,8,9,10}, {11,12,13,14,15}}; 8 | double arr2[rows][cols]; 9 | for(i=0; i 2 | #define YEAR 5 3 | #define MONTH 12 4 | void perYearFall(const double [][MONTH], int); 5 | void perMonthFall(const double [][MONTH], int); 6 | 7 | int main(void){ 8 | const double a[YEAR][MONTH] = { 9 | {4.3, 4.3, 4.3, 3.0, 2.0, 1.2, 0.2, 0.2, 0.4, 2.4, 3.5, 6.6}, 10 | {8.5, 8.2, 1.2, 1.6, 2.4, 0.0, 5.2, 0.9, 0.3, 0.9, 1.4, 7.3}, 11 | {9.1, 8.5, 6.7, 4.3, 2.1, 0.8, 0.2, 0.2, 1.1, 2.3, 6.1, 8.4}, 12 | {7.2, 9.9, 8.4, 3.3, 1.2, 0.8, 1.4, 0.0, 0.6, 1.7, 4.3, 6.2}, 13 | {7.6, 5.6, 3.8, 2.8, 3.8, 0.2, 0.0, 0.0, 0.0, 1.3, 2.6, 5.2} 14 | }; 15 | perYearFall(a, YEAR); 16 | perMonthFall(a, YEAR); 17 | return 0; 18 | } 19 | void perYearFall(const double a[][MONTH], int year){ 20 | int i, j; 21 | double yearFall, sumYearFall; 22 | for(i = 0; i < year; i++) 23 | { 24 | yearFall = 0; 25 | for(j = 0; j < MONTH; j++) 26 | yearFall += a[i][j]; 27 | printf("%dyear\t\t%.2lf(inches)\n", i+2010, yearFall); 28 | sumYearFall += yearFall; 29 | } 30 | printf("\nthe yearly average is %.2lf\n\n", sumYearFall/year); 31 | 32 | } 33 | void perMonthFall(const double a[][MONTH], int year){ 34 | int i, j; 35 | double monthFall; 36 | for (i = 0; i < MONTH; ++i) 37 | { 38 | monthFall = 0; 39 | for (j = 0; j < year; ++j) 40 | monthFall += a[j][i]; 41 | printf("%.2lf ", monthFall/5); 42 | } 43 | } -------------------------------------------------------------------------------- /articals/c/Demo/test78.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/suoyuesmile/suo-blog/6068b6934e0bcae9b189fcefdc6a6d3752295a29/articals/c/Demo/test78.exe -------------------------------------------------------------------------------- /articals/c/Demo/test79.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/suoyuesmile/suo-blog/6068b6934e0bcae9b189fcefdc6a6d3752295a29/articals/c/Demo/test79.exe -------------------------------------------------------------------------------- /articals/c/Demo/test8.c: -------------------------------------------------------------------------------- 1 | #include 2 | void one_three(); 3 | void two(); 4 | int main(){ 5 | printf("starting now:\n"); 6 | one_three(); 7 | printf("done\n"); 8 | return 0; 9 | } 10 | void one_three(){ 11 | printf("one\n"); 12 | two(); 13 | printf("three\n"); 14 | } 15 | void two(){ 16 | printf("two\n"); 17 | } -------------------------------------------------------------------------------- /articals/c/Demo/test8.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/suoyuesmile/suo-blog/6068b6934e0bcae9b189fcefdc6a6d3752295a29/articals/c/Demo/test8.exe -------------------------------------------------------------------------------- /articals/c/Demo/test80.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main(void){ 3 | return 0; 4 | } -------------------------------------------------------------------------------- /articals/c/Demo/test81.c: -------------------------------------------------------------------------------- 1 | #include 2 | #define N 50 3 | void getStr(char *, int ); 4 | int main(void){ 5 | char a[N]; 6 | getStr(a, N); 7 | puts(a); 8 | return 0; 9 | } 10 | void getStr(char * a, int n){ 11 | while( n-- > 0){ 12 | a[n] = getchar(); 13 | } 14 | } -------------------------------------------------------------------------------- /articals/c/Demo/test81.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/suoyuesmile/suo-blog/6068b6934e0bcae9b189fcefdc6a6d3752295a29/articals/c/Demo/test81.exe -------------------------------------------------------------------------------- /articals/c/Demo/test82.c: -------------------------------------------------------------------------------- 1 | #include 2 | #define N 50 3 | void getStr(char *, int ); 4 | int main(void){ 5 | char a[N];; 6 | getStr(a, N); 7 | puts(a); 8 | return 0; 9 | } 10 | void getStr(char * a, int n) { 11 | int i = 0; 12 | while( i++ < n){ 13 | a[i] = getchar(); 14 | if(a[i] == '\n' || a[i] == '\t' || a[i] == '\0') { 15 | break; 16 | } 17 | } 18 | } -------------------------------------------------------------------------------- /articals/c/Demo/test82.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/suoyuesmile/suo-blog/6068b6934e0bcae9b189fcefdc6a6d3752295a29/articals/c/Demo/test82.exe -------------------------------------------------------------------------------- /articals/c/Demo/test83.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | void reStr(char *, int); 4 | int main(void){ 5 | char str[20]; 6 | while( fgets(str, 20, stdin) ){ 7 | reStr(str, strlen(str)); 8 | fputs(str, stdout); 9 | } 10 | return 0; 11 | } 12 | void reStr(char * a, int n){ 13 | int i = 0; 14 | char b[n]; 15 | while(i++ < n) 16 | b[i] = a[i-1]; 17 | i = 0; 18 | while(n-- >= 0){ 19 | a[i] = b[n]; 20 | i++; 21 | } 22 | } -------------------------------------------------------------------------------- /articals/c/Demo/test83.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/suoyuesmile/suo-blog/6068b6934e0bcae9b189fcefdc6a6d3752295a29/articals/c/Demo/test83.exe -------------------------------------------------------------------------------- /articals/c/Demo/test84.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main(void){ 3 | 4 | return 0; 5 | } -------------------------------------------------------------------------------- /articals/c/Demo/test85.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #define N 10 4 | int main(void){ 5 | char a[N]; 6 | int i, word, up, low, num, pun; 7 | int countWord, countUp, countLow, countNum, countPun; 8 | while( fgets(a, N, stdin) != NULL && a[0] != '\n'){ 9 | i = 0, num=0, low=0, up=0, pun=0, word=0; 10 | if(a[i] == '\n') 11 | a[i] == ' '; 12 | if(isblank(a[i])) 13 | word++; 14 | else if(isdigit(a[i])) 15 | num++; 16 | else if(islower(a[i])) 17 | low++; 18 | else if(isupper(a[i])) 19 | up++; 20 | else 21 | pun++; 22 | } 23 | return 0; 24 | } 25 | 26 | -------------------------------------------------------------------------------- /articals/c/Demo/test86.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main(int argc, char * argv[]){ 3 | int i = argc; 4 | printf("%d\n", argc); 5 | while( i-- > 1 ) 6 | puts(argv[i]); 7 | } 8 | // --i情况 (没想到argc = 4) (- -) 9 | // test86 see you later 0 1 2 3 10 | // 1) (i = 4- 1 = 3, i > 0) -> a[3] 11 | // 2) (i = 3- 1 = 2, i > 0) -> a[2] 12 | // i--情况 13 | // 1) (i = 4 > 0, i = 3 - 1 = 2) -> a[3] 14 | // 2) (i = 3 > 0, i = 2 - 1 = 2) -> a[2] 15 | // 3) (i = 2 > 0, i = 1 - 1 = 1) -> a[1] -------------------------------------------------------------------------------- /articals/c/Demo/test86.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/suoyuesmile/suo-blog/6068b6934e0bcae9b189fcefdc6a6d3752295a29/articals/c/Demo/test86.exe -------------------------------------------------------------------------------- /articals/c/Demo/test87.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/suoyuesmile/suo-blog/6068b6934e0bcae9b189fcefdc6a6d3752295a29/articals/c/Demo/test87.c -------------------------------------------------------------------------------- /articals/c/Demo/test88.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #define N 10 4 | void pf(char * , int); 5 | void toUpper(char * , int); 6 | void toLower(char * , int); 7 | int main(int argc, char * argv[]){ 8 | char a[N]; 9 | switch (argv[1][1]){ 10 | case 'p': pf(a, N); break; 11 | case 'u': toUpper(a, N); break; 12 | case 'l': toLower(a, N); break; 13 | default : puts("enter error!"); break; 14 | } 15 | return 0; 16 | } 17 | //原样输出 18 | void pf(char * a, int n){ 19 | while( fgets(a, n, stdin) != NULL && a[0] != '\n'){ 20 | fputs(a, stdout); 21 | } 22 | 23 | } 24 | //输出大写 25 | void toLower(char * a, int n){ 26 | int i; 27 | while( fgets(a, n, stdin) != NULL && a[0] != '\n'){ 28 | i = 0; 29 | while(i++ < n-1){ // i=0<9 i=1 a[0], i=1<9 i=2 a[1] ---> i=8<9 i=9 a[8] 30 | if(isupper(a[i-1])) 31 | a[i-1] = tolower(a[i-1]); 32 | } 33 | fputs(a, stdout); 34 | } 35 | } 36 | //输出小写 37 | void toUpper(char * a, int n){ 38 | int i; 39 | while( fgets(a, n, stdin) != NULL && a[0] != '\n'){ 40 | i = 0; 41 | while(i++ < n-1){ 42 | if(islower(a[i-1])) 43 | a[i-1] = toupper(a[i-1]); 44 | } 45 | fputs(a, stdout); 46 | } 47 | } 48 | 49 | -------------------------------------------------------------------------------- /articals/c/Demo/test88.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/suoyuesmile/suo-blog/6068b6934e0bcae9b189fcefdc6a6d3752295a29/articals/c/Demo/test88.exe -------------------------------------------------------------------------------- /articals/c/Demo/test89.c: -------------------------------------------------------------------------------- 1 | #include 2 | // int units = 0; 3 | void critic(int ); 4 | int main(){ 5 | int units = 0; 6 | scanf("%d", &units); 7 | if(units != 56) 8 | critic(units); 9 | return 0; 10 | } 11 | void critic(int u){ 12 | printf("%d\n", u); 13 | } -------------------------------------------------------------------------------- /articals/c/Demo/test89.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/suoyuesmile/suo-blog/6068b6934e0bcae9b189fcefdc6a6d3752295a29/articals/c/Demo/test89.exe -------------------------------------------------------------------------------- /articals/c/Demo/test9.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main(){ 3 | int n = 2147483647; 4 | float f = 1e+20; 5 | float f1 = -f; 6 | printf("n = %d, n+1 = %d\n", n, n+1); 7 | printf("f = %f, f+1 = %f\n", f, f+1); 8 | printf("f1 = %f, f1+1 = %f\n", f1, f1-1); 9 | return 0; 10 | } -------------------------------------------------------------------------------- /articals/c/Demo/test9.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/suoyuesmile/suo-blog/6068b6934e0bcae9b189fcefdc6a6d3752295a29/articals/c/Demo/test9.exe -------------------------------------------------------------------------------- /articals/c/Demo/test90.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main(void){ 3 | int mode; 4 | printf("enter 0 for metric, 1 for Us mode:\n"); 5 | while(scanf("%d", &mode) == 1 && mode >= 0){ 6 | set_mode(mode); 7 | get_info(); 8 | show_info(); 9 | printf("enter 0 for metric, 1 for Us mode:\n"); 10 | printf("-1 to quit:"); 11 | } 12 | return 0; 13 | } -------------------------------------------------------------------------------- /articals/c/Demo/test91.c: -------------------------------------------------------------------------------- 1 | #include "test91.h" 2 | void set_mode(int mode){ 3 | if(mode == 0) 4 | fule = distance/kalub; 5 | if(mode == 1) 6 | fule = distance/kalub*100; 7 | } 8 | void get_info(void){ 9 | printf("enter a kalub, distance, fule:"); 10 | scanf("%lf%lf%lf", kalub, distance, fule); 11 | } 12 | void show_info(void){ 13 | printf("%d\n", fule); 14 | } -------------------------------------------------------------------------------- /articals/c/Demo/test91.h: -------------------------------------------------------------------------------- 1 | #include 2 | double kalub; 3 | double distance; 4 | double fule; 5 | void set_mode(int); 6 | void show_info(void); 7 | void get_info(void); -------------------------------------------------------------------------------- /articals/c/Demo/test92.c: -------------------------------------------------------------------------------- 1 | #include 2 | static int i = 0; 3 | int a(void); 4 | int main(){ 5 | int n = 10; 6 | while( n-- ) 7 | printf("%d\n", a()); 8 | } 9 | int a(void){ 10 | return ++i; 11 | } -------------------------------------------------------------------------------- /articals/c/Demo/test92.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/suoyuesmile/suo-blog/6068b6934e0bcae9b189fcefdc6a6d3752295a29/articals/c/Demo/test92.exe -------------------------------------------------------------------------------- /articals/c/Demo/test93.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/suoyuesmile/suo-blog/6068b6934e0bcae9b189fcefdc6a6d3752295a29/articals/c/Demo/test93.c -------------------------------------------------------------------------------- /articals/c/Demo/test94.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #define N 1000 5 | int rand1(int); 6 | void count(const int *, int); 7 | int main(){ 8 | int a[N] = {0}; 9 | srand( (unsigned int) time(0) ); 10 | for (int i = 0; i < N; ++i) 11 | { 12 | a[i] = rand1(10); 13 | } 14 | count(a, N); 15 | } 16 | //产生随机数 17 | int rand1(int n){ 18 | return rand() % n + 1; 19 | } 20 | //计算每个数产生的个数 21 | void count( const int *a, int n){ 22 | int b[10] = {0}; 23 | for(int j = 0; j < 10; ++j) 24 | for(int i = 0; i < n; ++i) 25 | if(a[i] == j+1) 26 | b[j]++; 27 | for (int i = 0; i < 10; ++i) 28 | printf("%d\n", b[i]); 29 | } -------------------------------------------------------------------------------- /articals/c/Demo/test94.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/suoyuesmile/suo-blog/6068b6934e0bcae9b189fcefdc6a6d3752295a29/articals/c/Demo/test94.exe -------------------------------------------------------------------------------- /articals/c/Demo/test95.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #define N 100 5 | int rand1(int); 6 | void sort(int *, int); 7 | void show(const int *, int); 8 | int main(){ 9 | int a[N] = {0}; 10 | srand( (unsigned int) time(0) ); 11 | for (int i = 0; i < N; ++i) 12 | { 13 | a[i] = rand1(10); 14 | } 15 | show(a, N); 16 | sort(a, N); 17 | putchar('\n'); 18 | show(a, N); 19 | } 20 | //产生随机数 21 | int rand1(int n){ 22 | return rand() % n + 1; 23 | } 24 | //选择排序 25 | void sort(int *a, int n){ 26 | for (int top = 0; top < n - 1; ++top) 27 | for (int seek = top + 1; seek < n; ++seek) 28 | if( a[top] < a[seek]){ 29 | int tmp = a[top]; 30 | a[top] = a[seek]; 31 | a[seek] = tmp; 32 | } 33 | } 34 | //打印数组 35 | void show( const int *a, int n){ 36 | for (int i = 0; i < n; ++i) 37 | { 38 | printf("%d ", a[i]); 39 | } 40 | } -------------------------------------------------------------------------------- /articals/c/Demo/test95.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/suoyuesmile/suo-blog/6068b6934e0bcae9b189fcefdc6a6d3752295a29/articals/c/Demo/test95.exe -------------------------------------------------------------------------------- /articals/c/Demo/test96.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #define SIZE 20 4 | int get_n(){ 5 | int words; 6 | if(scanf("%d", &words) == 1 && words > 0) 7 | return words; 8 | else 9 | printf("enter error!!!\n"); 10 | } 11 | void show(char * a[], int n){ 12 | int i = 0; 13 | while( i++ < n ){ 14 | puts(a[i-1]); 15 | } 16 | } 17 | int main(void){ 18 | int words, i = 0, j = 0; 19 | char ch; 20 | printf("how many words do you wish to enter:"); 21 | words = get_n(); //处理输入的单词数 22 | // char * q [5] = (char (*) [5])malloc( SIZE * 5 * sizeof(char) ); 23 | //动态创建 24 | printf("enter %d words:", words); 25 | while( (ch = getchar()) != '\n' ){ 26 | if(ch == ' ') 27 | { 28 | char * p = (char *)malloc( i * sizeof(char) ); 29 | q[j] = p; 30 | free( p ); 31 | j++; 32 | i = 0; 33 | continue; 34 | } 35 | i++; 36 | } 37 | show(q, words); 38 | free( q ); 39 | return 0; 40 | } -------------------------------------------------------------------------------- /articals/c/Demo/test97.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #define SIZE 512 4 | int main(int argc, char * argv[]){ 5 | FILE *in, *out; 6 | char buff[SIZE]; 7 | //读文件到缓冲区 8 | if( (in = fopen(argv[1], "r")) == NULL ){ 9 | fputs("error", stderr); 10 | exit(EXIT_FAILURE); 11 | } 12 | fread(buff, SIZE, 1, in); 13 | //从缓冲区写文件 14 | if( (out = fopen(argv[2], "w")) == NULL ) { 15 | fputs("error", stderr); 16 | exit(EXIT_FAILURE); 17 | } 18 | fwrite(buff, SIZE, 1, out); 19 | //关闭文件 20 | if( fclose(in) != 0 || fclose(out) != 0 ) 21 | fputs("not close", stderr); 22 | return 0; 23 | } 24 | -------------------------------------------------------------------------------- /articals/c/Demo/test97.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/suoyuesmile/suo-blog/6068b6934e0bcae9b189fcefdc6a6d3752295a29/articals/c/Demo/test97.exe -------------------------------------------------------------------------------- /articals/c/Demo/test98.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #define SIZE 512 5 | int main(){ 6 | char *infile, *outfile; 7 | FILE *in, *out; 8 | char buff[SIZE]; 9 | //输入到缓冲区 10 | printf("enter a in file:"); 11 | scanf("%s", &infile); 12 | if( (in = fopen(infile, "r") ) == NULL ){ 13 | fputs("std in eror", stderr); 14 | exit(EXIT_FAILURE); 15 | } 16 | fgets(buff, in); 17 | //从缓冲区输出到文件 18 | printf("enter a out file:"); 19 | scanf("%s", &outfile); 20 | if( (out = fopen(outfile, "w") ) == NULL ){ 21 | fputs("std out eror", stderr); 22 | exit(EXIT_FAILURE); 23 | } 24 | fputs(buff, out); 25 | return 0; 26 | } -------------------------------------------------------------------------------- /articals/c/Demo/test98.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/suoyuesmile/suo-blog/6068b6934e0bcae9b189fcefdc6a6d3752295a29/articals/c/Demo/test98.exe -------------------------------------------------------------------------------- /articals/c/Demo/test99.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | -------------------------------------------------------------------------------- /articals/c/Demo/testDice_d.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include "testRandom.c" 5 | int main(void){ 6 | int dice, roll; 7 | int sides, status; 8 | srand((unsigned int) time(0)); 9 | printf("enter a number of sides:\n"); 10 | while(scanf("%d", &sides) == 1 && sides > 0){ 11 | printf("how many dice\n"); 12 | //检查输入部分 13 | if(status = scanf("%d", &dice) != 1){ 14 | if(status == EOF) //检查是否有文件终止符 15 | break; 16 | else{ 17 | while(getchar() != '\n') //去掉换行符 18 | continue; 19 | continue; 20 | } 21 | } 22 | //开始计算骰子总和 23 | roll = roll_n_dice(dice, sides); 24 | //打印结果 25 | printf("total %d , using %d times, %d-sides\n", roll, dice, sides); 26 | } 27 | printf("function called : %d\n", roll_count); 28 | return 0; 29 | } -------------------------------------------------------------------------------- /articals/c/Demo/testDice_d.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/suoyuesmile/suo-blog/6068b6934e0bcae9b189fcefdc6a6d3752295a29/articals/c/Demo/testDice_d.exe -------------------------------------------------------------------------------- /articals/c/Demo/testFgets.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main(void){ 3 | char a[10]; 4 | fgets(a, 7, stdin); //读了dsfdsf个字符+'\0' 5 | fputs(a, stdout); //输出dsfdsf\0 没有+'\n' 6 | return 0; 7 | } 8 | //dsfdsfsdgfdgdffdg 9 | //dsfdsf -------------------------------------------------------------------------------- /articals/c/Demo/testFgets.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/suoyuesmile/suo-blog/6068b6934e0bcae9b189fcefdc6a6d3752295a29/articals/c/Demo/testFgets.exe -------------------------------------------------------------------------------- /articals/c/Demo/testFgets2.c: -------------------------------------------------------------------------------- 1 | #include 2 | #define N 10 3 | int main(void){ 4 | char word[N]; 5 | while( fgets(word, N, stdin) != NULL && word[0] != '\n' ){ 6 | fputs(word, stdout); 7 | } 8 | return 0; 9 | } -------------------------------------------------------------------------------- /articals/c/Demo/testFgets2.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/suoyuesmile/suo-blog/6068b6934e0bcae9b189fcefdc6a6d3752295a29/articals/c/Demo/testFgets2.exe -------------------------------------------------------------------------------- /articals/c/Demo/testFgets3.c: -------------------------------------------------------------------------------- 1 | #include 2 | #define N 10 3 | int main(){ 4 | char word[N]; 5 | int i; 6 | while( fgets(word, N, stdin) != NULL && word[0] != '\n'){ 7 | i = 0; 8 | while(word[i] != '\n' && word[i] != '\0') 9 | i++; //不是换行符或者空字符跳过 10 | if(word[i] == '\n') 11 | word[i] = '\0'; //遇到换行符,转空字符 12 | else 13 | while(getchar() != '\n') //读到空字符,丢弃剩余 14 | continue; 15 | fputs(word, stdout); 16 | } 17 | return 0; 18 | } -------------------------------------------------------------------------------- /articals/c/Demo/testFgets3.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/suoyuesmile/suo-blog/6068b6934e0bcae9b189fcefdc6a6d3752295a29/articals/c/Demo/testFgets3.exe -------------------------------------------------------------------------------- /articals/c/Demo/testFileIO.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main(){ 3 | char ch; 4 | while( (ch = getchar()) != EOF){ 5 | putchar(ch); 6 | } 7 | return 0; 8 | } -------------------------------------------------------------------------------- /articals/c/Demo/testFileIO.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/suoyuesmile/suo-blog/6068b6934e0bcae9b189fcefdc6a6d3752295a29/articals/c/Demo/testFileIO.exe -------------------------------------------------------------------------------- /articals/c/Demo/testGets.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main(void){ 3 | char name[10]; 4 | gets(name); 5 | puts(name); 6 | return 0; 7 | } 8 | //fgdfgdfgdfgfdgfdg 9 | //fgdfgdfgdfgfdgfdg -------------------------------------------------------------------------------- /articals/c/Demo/testGets.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/suoyuesmile/suo-blog/6068b6934e0bcae9b189fcefdc6a6d3752295a29/articals/c/Demo/testGets.exe -------------------------------------------------------------------------------- /articals/c/Demo/testIO.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | int main(int argc, char * argv[]){ 4 | int ch; //读取文件,存储每个字符的地方 5 | FILE *fp; //文件指针 6 | unsigned long count = 0; 7 | if(argc != 2){ 8 | printf("Usage: %s filename \n", argv[0]); 9 | } 10 | if( (fp = fopen(argv[1], "r")) == NULL ){ 11 | printf("can't open %s\n", argv[1]); 12 | exit(EXIT_FAILURE); 13 | } 14 | while( (ch = getc(fp)) != EOF ){ 15 | putc(ch, stdout); 16 | count++; 17 | } 18 | fclose(fp); 19 | printf("File %s has %lu characters\n", argv[1], count); 20 | return 0; 21 | 22 | } -------------------------------------------------------------------------------- /articals/c/Demo/testIO.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/suoyuesmile/suo-blog/6068b6934e0bcae9b189fcefdc6a6d3752295a29/articals/c/Demo/testIO.exe -------------------------------------------------------------------------------- /articals/c/Demo/testP02.c: -------------------------------------------------------------------------------- 1 | #include 2 | int a[2] = {1, 2}; 3 | int main(){ 4 | int *p1, *p2, *p3; 5 | p1 = p2 = p3 = a; 6 | printf("%d,%d,%d\n", *p1, *p1++, *p1); 7 | //分析: 函数中参数的传递的顺序是从右往左传递 8 | // 1.*p1 = 1 ==> no3 = 1 9 | // 2.*p1++ ==> *p1 = 1 , p1 += 1; ==> no2 = 1 10 | // 3.*p1 ==> a[1] ==> no3 = 2 11 | printf("%d,%d,%d\n", *p2, (*p2)++, *p2); 12 | // 1.*p2 = 1 ==> no3 = 1 13 | // 2.(*p2)++ ==> *p2 = a[0], no2 = 1, a[0] = 2 14 | // 3.*p2 = a[0] = 2 ==> no1 = 2; 15 | printf("%d,%d,%d\n", *p3, *++p3, *p3); 16 | // 1.*p3 = a[0] ==> no3 = 2 17 | // 2.*++p3 ==> p3= p3+1 = &a[1] => no2 = *&a[1] = 2 18 | // 3.*p3 = a[1] = 2 ==> no1 = 2; 19 | return 0; 20 | } 21 | // 2 1 1 22 | // 2 1 1 23 | // 2 2 2 -------------------------------------------------------------------------------- /articals/c/Demo/testP02.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/suoyuesmile/suo-blog/6068b6934e0bcae9b189fcefdc6a6d3752295a29/articals/c/Demo/testP02.exe -------------------------------------------------------------------------------- /articals/c/Demo/testPntAdd.c: -------------------------------------------------------------------------------- 1 | #include 2 | #define SIZE 10 3 | int main(){ 4 | short a[SIZE] = {1,2,3,4,5,6,7,8,9,10}; 5 | double b[SIZE] = {1,2,3,4,5,6,7,8,9,10}; 6 | short i, *pa = a; 7 | double *pb = b; 8 | for (i = 0; i < 2; ++i) 9 | { 10 | printf("pa%d point %p\n", i, pa++); 11 | } 12 | for (i = 0; i < 2; ++i) 13 | { 14 | printf("pb%d point %p\n", i, pb++); 15 | } 16 | } 17 | // pa0 point 0060FF00 18 | // pa1 point 0060FF02 19 | 20 | // pb0 point 0060FEB0 21 | // pb1 point 0060FEB8 22 | -------------------------------------------------------------------------------- /articals/c/Demo/testPntAdd.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/suoyuesmile/suo-blog/6068b6934e0bcae9b189fcefdc6a6d3752295a29/articals/c/Demo/testPntAdd.exe -------------------------------------------------------------------------------- /articals/c/Demo/testPo.c: -------------------------------------------------------------------------------- 1 | #include 2 | #define SIZE 4 3 | int sum(int * start, int * end){ 4 | int sum = 0; 5 | while(start < end){ 6 | sum += *start++; 7 | //分析 * ++(后缀) 同优先级右结合 8 | //步骤分解 1. start先使用用 sum = sum + *start; 9 | // 2. start = start + 1; 10 | } 11 | return sum; 12 | } 13 | int main(void){ 14 | int a[SIZE] = {1, 2 , 3, 4}; 15 | printf("%d", sum(a, a+SIZE)); 16 | return 0; 17 | } 18 | // 10 正确 19 | -------------------------------------------------------------------------------- /articals/c/Demo/testPo.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/suoyuesmile/suo-blog/6068b6934e0bcae9b189fcefdc6a6d3752295a29/articals/c/Demo/testPo.exe -------------------------------------------------------------------------------- /articals/c/Demo/testPoint.c: -------------------------------------------------------------------------------- 1 | #include 2 | int arr(int); 3 | int main(void){ 4 | int (* p)(int); 5 | p = arr; 6 | printf("%p,%p\n", p, arr); 7 | return 0; 8 | } 9 | int arr(int n){ 10 | return n; 11 | } 12 | //00401499,00401499 -------------------------------------------------------------------------------- /articals/c/Demo/testPoint.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/suoyuesmile/suo-blog/6068b6934e0bcae9b189fcefdc6a6d3752295a29/articals/c/Demo/testPoint.exe -------------------------------------------------------------------------------- /articals/c/Demo/testPrintfScanf.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main(){ 3 | int a = 0, b =0; 4 | int pn1 = printf("ok!\n"); // pn1 = 4 5 | int pn2 = printf("ok!,%d,%d\n",a, b); // pn2 = 8 6 | int sn1 = scanf("%d", &a, &b); // sn1 = 1 7 | int sn2 = scanf("%d%d", &a, &b); // sn2 = 2 8 | printf("pn1=%d, sn1=%d, pn2=%d, sn2=%d\n", pn1, sn1, pn2, sn2); 9 | return 0; 10 | } -------------------------------------------------------------------------------- /articals/c/Demo/testPrintfScanf.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/suoyuesmile/suo-blog/6068b6934e0bcae9b189fcefdc6a6d3752295a29/articals/c/Demo/testPrintfScanf.exe -------------------------------------------------------------------------------- /articals/c/Demo/testR_d.c: -------------------------------------------------------------------------------- 1 | #include 2 | extern unsigned int rand0(void); 3 | extern void changeNext(unsigned int); 4 | int main(void){ 5 | unsigned int seed; 6 | while( scanf("%u", &seed) == 1 ){ 7 | changeNext(seed); 8 | for (int i = 0; i < 5; ++i) 9 | printf("%d\n", rand0()); 10 | } 11 | return 0; 12 | } -------------------------------------------------------------------------------- /articals/c/Demo/testR_d.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/suoyuesmile/suo-blog/6068b6934e0bcae9b189fcefdc6a6d3752295a29/articals/c/Demo/testR_d.exe -------------------------------------------------------------------------------- /articals/c/Demo/testRand.c: -------------------------------------------------------------------------------- 1 | #include 2 | static unsigned long int next = 1; //种子 3 | unsigned int rand0(void){ 4 | next = next * 1103515245 + 12345; 5 | return (unsigned int) (next / 65536) % 32768; 6 | } 7 | void changeNext(unsigned int seed){ 8 | next = seed; 9 | } 10 | -------------------------------------------------------------------------------- /articals/c/Demo/testRandom.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | int roll_count = 0; 4 | int roll_n_dice(int, int); 5 | int rollem(int); 6 | // int main(void){ 7 | // for (int i = 0; i < 10; ++i) 8 | // { 9 | // printf("%d\n", rollem(6)); 10 | // } 11 | // return 0; 12 | // } 13 | //生成1 - 6 之间的随机数 14 | int rollem(int sides){ 15 | int roll; 16 | roll = rand() % sides + 1; 17 | roll_count++; 18 | return roll; 19 | } 20 | int roll_n_dice(int dice, int sides){ 21 | int d; 22 | int total = 0; 23 | if(sides < 2) 24 | return -2; 25 | if(sides < 1) 26 | return -1; 27 | for (d = 0; d < dice; ++d) 28 | total += rollem(sides); 29 | return total; 30 | } -------------------------------------------------------------------------------- /articals/c/Demo/testRandom.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/suoyuesmile/suo-blog/6068b6934e0bcae9b189fcefdc6a6d3752295a29/articals/c/Demo/testRandom.exe -------------------------------------------------------------------------------- /articals/c/Demo/testRecursion.c: -------------------------------------------------------------------------------- 1 | #include 2 | int up_and_down(int); 3 | int main(void){ 4 | up_and_down( 1 ); 5 | return 0; 6 | } 7 | int up_and_down(int n){ 8 | printf("%d, %p\n", n, &n); 9 | if(n < 4) 10 | up_and_down( n + 1 ); 11 | printf("%d, %p\n", n, &n); 12 | } 13 | // 1, 0060FF20 14 | // 2, 0060FF00 15 | // 3, 0060FEE0 16 | // 4, 0060FEC0 17 | // 4, 0060FEC0 18 | // 3, 0060FEE0 19 | // 2, 0060FF00 20 | // 1, 0060FF20 -------------------------------------------------------------------------------- /articals/c/Demo/testRecursion.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/suoyuesmile/suo-blog/6068b6934e0bcae9b189fcefdc6a6d3752295a29/articals/c/Demo/testRecursion.exe -------------------------------------------------------------------------------- /articals/c/Demo/testReducto.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #define N 40 5 | int main(int argc, char * argv[]){ 6 | FILE *in, *out; 7 | int ch; 8 | char name[N]; 9 | int count; 10 | //检查命令行参数 11 | if(argc < 2){ 12 | fprintf(stderr, "Usage:%s filename\n", argv[0]); 13 | exit(EXIT_FAILURE); 14 | } 15 | //设置输入 16 | if( (in = fopen(argv[1], "r")) == NULL){ 17 | fprintf(stderr, "I could not open this file\" %s \" \n ", argv[1]); 18 | exit(EXIT_FAILURE); 19 | } 20 | //设置输出 21 | strncpy(name, argv[1], N - 5); 22 | name[N -5] = '\0'; 23 | strcat(name, ".red"); 24 | if( (out = fopen(name, "w")) == NULL ){ 25 | fprintf(stderr, "I could not open this file"); 26 | exit(3); 27 | } 28 | //拷贝 29 | while( (ch = getc(in)) != EOF ){ 30 | if (count++ % 3 == 0) 31 | putc(ch, out); 32 | } 33 | //关闭文件 34 | if( fclose(in) != 0 || fclose(out) != 0 ) 35 | fprintf(stderr, "Error in closing files\n"); 36 | return 0; 37 | } -------------------------------------------------------------------------------- /articals/c/Demo/testReducto.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/suoyuesmile/suo-blog/6068b6934e0bcae9b189fcefdc6a6d3752295a29/articals/c/Demo/testReducto.exe -------------------------------------------------------------------------------- /articals/c/Demo/testScope.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main(void){ 3 | int i = 1 ; 4 | // for (int i = 0; i < 10; ++i) 5 | // { 6 | // // int i = 6; 7 | // printf("%d ", i); 8 | // } 9 | printf("block:%d\n", i); 10 | return 0; 11 | } 12 | // 0 1 2 3 4 5 6 7 8 9 file:3 -------------------------------------------------------------------------------- /articals/c/Demo/testStrSort.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #define SIZE 81 //字符串长度 4 | #define LIM 20 //最大行数 5 | #define HALT "" //读到空字符结束 6 | void strSort(char * str [], int num); //排序函数 7 | char * strGets(char * , int ); //输入字符串函数 8 | 9 | int main(void){ 10 | char in[LIM][SIZE]; 11 | char * pstr[LIM]; 12 | int ct = 0, k = 0; //输入输出计数 13 | while(ct < LIM && strGets(in[ct], SIZE) != NULL && in[ct][0] != '\0'){ 14 | pstr[ct] = in[ct]; 15 | ct++; //输入字符串 16 | } 17 | strSort(pstr, ct); //排序字符串 18 | for(k = 0; k < ct; k++) 19 | puts(pstr[k]); //输出字符串 20 | return 0; 21 | } 22 | //选择排序 23 | void strSort(char * str [], int num){ 24 | char *temp; 25 | int top, seek; 26 | for (top = 0; top < num-1; ++top) 27 | { 28 | for (seek = top + 1; seek < num; ++seek) 29 | { 30 | if( strcmp(str[top], str[seek]) > 0 ) 31 | temp = str[top]; 32 | str[top] = str[seek]; 33 | str[seek] = temp; 34 | } 35 | } 36 | } 37 | //自定义输入函数 38 | char * strGets(char * str, int n){ 39 | char * ret_val; 40 | int i = 0; 41 | ret_val = fgets(str, n, stdin); 42 | if(ret_val){ 43 | while(str[i] != '\n' && str[i] != '\0') 44 | i++; 45 | if(str[i] == '\n') 46 | str[i] = '\0'; 47 | else 48 | while(getchar() != '\n') 49 | continue; 50 | } 51 | return ret_val; 52 | } -------------------------------------------------------------------------------- /articals/c/Demo/testStrSort.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/suoyuesmile/suo-blog/6068b6934e0bcae9b189fcefdc6a6d3752295a29/articals/c/Demo/testStrSort.exe -------------------------------------------------------------------------------- /articals/c/Demo/testSwap.c: -------------------------------------------------------------------------------- 1 | #include 2 | void swap(int *, int *); 3 | int main(void){ 4 | int a = 1, b =2; 5 | swap(&a, &b); 6 | printf("%d, %d\n", a, b); 7 | return 0; 8 | } 9 | void swap(int *p, int * q){ 10 | int temp; 11 | temp = *p; 12 | *p = *q; 13 | *q = temp; 14 | } -------------------------------------------------------------------------------- /articals/c/Demo/testSwap.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/suoyuesmile/suo-blog/6068b6934e0bcae9b189fcefdc6a6d3752295a29/articals/c/Demo/testSwap.exe -------------------------------------------------------------------------------- /articals/c/Demo/testToBinary.c: -------------------------------------------------------------------------------- 1 | #include 2 | void to_binary(int); 3 | int main(void){ 4 | int n; 5 | scanf("%d", &n); 6 | to_binary(n); 7 | return 0; 8 | } 9 | 10 | void to_binary(int n){ 11 | int r; 12 | r = n % 2; 13 | if( n >= 2 ) 14 | to_binary( n/2 ); 15 | printf("%d", r==0 ? 0 : 1); 16 | } -------------------------------------------------------------------------------- /articals/c/Demo/testToBinary.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/suoyuesmile/suo-blog/6068b6934e0bcae9b189fcefdc6a6d3752295a29/articals/c/Demo/testToBinary.exe -------------------------------------------------------------------------------- /articals/c/Demo/words: -------------------------------------------------------------------------------- 1 | Apple Banana 2 | Orager HongKong 3 | SHANGHAI wuhan -------------------------------------------------------------------------------- /articals/c/Demo/words.red: -------------------------------------------------------------------------------- 1 | AlBa 2 | aroKgHGIun -------------------------------------------------------------------------------- /articals/c/Demo/wordscp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/suoyuesmile/suo-blog/6068b6934e0bcae9b189fcefdc6a6d3752295a29/articals/c/Demo/wordscp -------------------------------------------------------------------------------- /booknotes/demo/AVL.class.cpp: -------------------------------------------------------------------------------- 1 | #define Balance(x) ( stature( (x).lChild ) == stature( (x).rChild ) ) 2 | #define BalFac(x) ( stature( (x).lChild ) - stature( (x).rChild ) ) 3 | #define AvlBalanced(x) ( ( -2 < BalFac(x) ) && ( BalFac(x) < 2 ) ) 4 | template class AVL: public BST { 5 | public: 6 | BinNodePosi(T) insert( const T &); //插入重写 7 | bool remove( const T &); //删除重写 8 | } 9 | //插入 10 | template BinNodePosi(T) AVL::insert( const T & e) { 11 | BinNodePosi(T) & x = search( e ); 12 | if( x ) return x; 13 | x = new BinNode( e, _hot ); 14 | _size++; 15 | BinNodePosi(T) xx = x; 16 | for ( BinNodePosi(T) g = x->parenr; g; g = g->parent ) 17 | if ( !AvlBalanced( *g ) ) { 18 | FromParentIo( *g ) = rotateAt( tallerChild( tallerChild(g) ) ); 19 | break; 20 | }else 21 | updateHeight( g ); 22 | return xx; 23 | } -------------------------------------------------------------------------------- /booknotes/demo/BTNode.h: -------------------------------------------------------------------------------- 1 | template struct BTNode { 2 | BTNodePosi(T) parent; //父 3 | Vector key; //数值向量 4 | Vector< BTNodePosi(T) > child; //孩子向量 5 | BTNode() { parent = NULL; child.insert(0, NULL); } 6 | BTNode( T e, BTNodePosi(T) lc = NULL, BTNodePosi(T) rc = NULL) { 7 | parent = NULL; //根节点 8 | key.insert( 0, e ); //仅一个关键码,以及两个孩子 9 | child.insert( 0, lc ); 10 | child.insert( 1, rc ); 11 | if( lc ) lc->parent = this; 12 | if( rc ) rc->parent = this; 13 | } 14 | } -------------------------------------------------------------------------------- /booknotes/demo/BTree.class.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/suoyuesmile/suo-blog/6068b6934e0bcae9b189fcefdc6a6d3752295a29/booknotes/demo/BTree.class.cpp -------------------------------------------------------------------------------- /booknotes/demo/BinNode.h: -------------------------------------------------------------------------------- 1 | #define BinNodePosi(T) BinNode* 2 | template struct BinNode { 3 | BinNodePosi(T) parent, lChild, rChild; //父亲孩子 4 | T data; //数据 5 | int height; //高度 6 | int size(); //规模 7 | BinNodePosi(T) insertAsLc(T const &); //插入左子 8 | BinNodePosi(T) insertAsRc(T const &); //插入右子 9 | BinNodePosi(T) succ(); //(中序)后继 10 | template void travLevel( VST & ); //层次遍历 11 | template void travIn( VST & ); //中序遍历 12 | template void travPost( VST & ); //后序遍历 13 | } //O(1) 14 | //插入左子 15 | template BinNodePosi(T) BinNode::insertAsLc(T const &) { 16 | return lChild = new BinNode( e, this); 17 | } 18 | //插入右子 19 | template BinNodePosi(T) BinNode::insertAsRc(T const &) { 20 | return rChild = new BinNode( e, this); 21 | }//O(1) 22 | //规模 23 | template int BinNode::size() { 24 | int s = 1; 25 | if (lChild) 26 | s += lChild->size(); 27 | if (rChild) 28 | s += rChild->size(); 29 | return s; 30 | }//O(n) -------------------------------------------------------------------------------- /booknotes/demo/Edge.h: -------------------------------------------------------------------------------- 1 | typedef enum { UNDETERMINED, TREE, CROSS, FORWORD, BACKWAED } EStatus; 2 | template struct Edge { 3 | Te data; //数据 4 | int weight; //权重 5 | EStatus status; //类型 6 | Edge( Te const & d, int w ):data(d), weight(w), status(UNDETERMINED) {} 7 | }; -------------------------------------------------------------------------------- /booknotes/demo/Graph.class.cpp: -------------------------------------------------------------------------------- 1 | template class Graph { 2 | private: 3 | void reset() { 4 | for (int i = 0; i < n; ++i){ //顶点 5 | status(i) = UNDISCOVERED; 6 | dTime(i) = fTime(i) = -1; 7 | parent(i) = -1; 8 | priority(i) = INT_MAX; 9 | for (int j = 0; j < n; j++) //边 10 | if (exists(i, j)) 11 | status(i, j) = UNDETERMINED; 12 | } 13 | } 14 | public: 15 | }; 16 | template void Graph::BFS(int v, int &clock) { 17 | Queue Q; 18 | status(v) = DISC 19 | } -------------------------------------------------------------------------------- /booknotes/demo/Lcs.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/suoyuesmile/suo-blog/6068b6934e0bcae9b189fcefdc6a6d3752295a29/booknotes/demo/Lcs.exe -------------------------------------------------------------------------------- /booknotes/demo/ListNode.h: -------------------------------------------------------------------------------- 1 | #define Post(T) ListNode* 2 | #define sPost(T) sListNode* 3 | template struct ListNode { //完全开放,不再过度封装 4 | T data; //数值 5 | Post(T) pred; //前驱 6 | Post(T) succ; //后继 7 | ListNode() {} //针对header和trailer的构造 8 | ListNode(T e, Posi(T) p = NULL, Post(T) s = NULL) : data(e), pred(p), succ(s) {} //默认构造 9 | Posi(T) insertAsPred(T const & e); //前插入 10 | Posi(T) insertAsSucc(T const & e); //后插入 11 | } 12 | template struct sListNode { //完全开放,不再过度封装 13 | T data; //数值 14 | Post(T) next; //后继 15 | ListNode() {} //针对header和trailer的构造 16 | ListNode(T e, Posi(T) p = NULL, Post(T) s = NULL) : data(e), pred(p), succ(s) {} //默认构造 17 | Posi(T) insertAsPred(T const & e); //前插入 18 | Posi(T) insertAsSucc(T const & e); //后插入 19 | } -------------------------------------------------------------------------------- /booknotes/demo/Node.h: -------------------------------------------------------------------------------- 1 | typedef *Node node(T); 2 | template struct Node { 3 | T data; 4 | node(T) next; 5 | } -------------------------------------------------------------------------------- /booknotes/demo/PQ.class.cpp: -------------------------------------------------------------------------------- 1 | template struct PQ{ 2 | virtual void insert(T) = 0; //按优先级插入词条 3 | virtual T getMax() = 0; //取出优先级最高的词条 4 | virtual T delMax() = 0; //删除优先级最高的词条 5 | }; //与其说是PQ是数据结构,不如说是ADT。根据不同的实现方式,适用于不同的场合 6 | #define Parent(i) ( (i-1) >> 1 ) 7 | #define LChild(i) ( 1 + ( ( i ) << 1 ) ) //奇数 8 | #define RChild(i) ( ( 1 + (i) ) << 1 ) //偶数 -------------------------------------------------------------------------------- /booknotes/demo/PQ_ComplHeap.class.cpp: -------------------------------------------------------------------------------- 1 | template class PQ_ComplHeap : public PQ , public Vector { 2 | protected: 3 | Rank percolateDown( Rank n, Rank i); //下滤 4 | Rank percolateUp( Rank i ); // 上滤 5 | void heapify( Rank n); //Floyd建堆算法 6 | public: 7 | PQ_ComplHead( T* A, Rank n) { copyFrom(A, 0, n); heapify(n); } 8 | //批量构造 9 | void insert(T); //按照比较器确定的优先级次序,插入词条 10 | T getMax() { return _elem[0]; } 11 | T delMax(); 12 | } -------------------------------------------------------------------------------- /booknotes/demo/Queue.class.cpp: -------------------------------------------------------------------------------- 1 | template class Queue : public List{ 2 | public: 3 | void enqueue(T const &e) { insertAsLast(e); } //入队 4 | T dequeue() { return remove( first() ); } //出队 5 | T & front() { return first()->data; } //队首 6 | }; -------------------------------------------------------------------------------- /booknotes/demo/RedBlack.class.cpp: -------------------------------------------------------------------------------- 1 | template class RedBlack: public BST { 2 | public: 3 | BinNodePosi(T) insert( const T & e); //插入重写 4 | bool remove( const T % e); // 删除重写 5 | protected: 6 | void solveDoubleRed( BinNodePosi(T) x); //双红修正 7 | void solveDoubleBlack( BinNodePosi(T) x); //双黑修正 8 | int updateHeight( BinNodePosi(T) x); //更新节点高度 9 | } -------------------------------------------------------------------------------- /booknotes/demo/SList.class.cpp: -------------------------------------------------------------------------------- 1 | #include "Node.h" 2 | template class SList { 3 | SList(int size); 4 | ~List(); 5 | void ClearSList(); 6 | bool SListEmoty(); 7 | int ListLength(); 8 | } 9 | template SList::SList() { 10 | 11 | } 12 | -------------------------------------------------------------------------------- /booknotes/demo/Splay.class.cpp: -------------------------------------------------------------------------------- 1 | template class Splay : public BST { 2 | protected: 3 | BinNodePosi(T) splay( BinNodePosi(T) v); //将v伸展至根 4 | public: //伸展树的查找也会引起整数的结构 5 | BinNodePosi(T) & search( const T & e); //查找 6 | BinNodePosi(T) insert( cosnt T & e); //插入 7 | bool remove( const T & e); //删除 8 | }; 9 | -------------------------------------------------------------------------------- /booknotes/demo/Stack.class.cpp: -------------------------------------------------------------------------------- 1 | template class Stack :public Vector { 2 | public: 3 | void push(T const & e) { insert(size(), e); } //入栈 4 | T pop() { return remove( size() -1 ); } //出栈 5 | T & top() { return (*this)[ size() - 1]; } //取顶 6 | }; -------------------------------------------------------------------------------- /booknotes/demo/SumI.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/suoyuesmile/suo-blog/6068b6934e0bcae9b189fcefdc6a6d3752295a29/booknotes/demo/SumI.exe -------------------------------------------------------------------------------- /booknotes/demo/VectorTest.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | using namespace std; 6 | 7 | int main() { 8 | // vector v; 9 | // v.push_back(1); 10 | // v.push_back(2); 11 | // cout << v[0] << v[1] << endl; 12 | stack s; 13 | s.push(1); 14 | s.push(2); 15 | cout << s.top(); 16 | s.pop(); 17 | cout << s.top() << endl; 18 | return 0; 19 | } -------------------------------------------------------------------------------- /booknotes/demo/VectorTest.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/suoyuesmile/suo-blog/6068b6934e0bcae9b189fcefdc6a6d3752295a29/booknotes/demo/VectorTest.exe -------------------------------------------------------------------------------- /booknotes/demo/Vertex.h: -------------------------------------------------------------------------------- 1 | typedef enum { UNDISCOVERED, DISCOVERED, VISITED} VStatus; 2 | template struct Vertex { 3 | Tc data; //数据 4 | int inDegree, outDegree; //入度出度 5 | VStatus status; //状态 6 | int dTime, fTime; //时间标签 7 | int parent; //父节点 8 | int priority; //优先级 9 | Vertex( Tv const & d) : //构造初始化新顶点 10 | data(d), inDegree(0), outDegree(0), 11 | status(UNDISCOVERED), dTime(-1), 12 | fTime(-1), priority(INT_MAX) {} 13 | } -------------------------------------------------------------------------------- /booknotes/demo/a_bubbleSort.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | //起泡排序 4 | void bubblesort(int A[], int n){ 5 | for( bool sorted = false; sorted = !sorted; n--) 6 | for(int i = 1; i < n; i++) 7 | if(A[i-1] > A[i]){ 8 | swap(A[i-1, A[i]]); 9 | sorted = false; 10 | } 11 | } 12 | int main(){ 13 | return 0; 14 | } -------------------------------------------------------------------------------- /booknotes/demo/a_convert.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | using namespace std; 5 | //进制转换 6 | void convert( Stack & S, __int64 n, int base) { 7 | static char digit[] = {'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'}; 8 | while (n > 0) { 9 | s.push( digit[ n % base ]); 10 | n /= base; 11 | } 12 | } 13 | int main() { 14 | Stack S; 15 | cin >> n >> base; 16 | convert(S, n, base); 17 | while ( !S.empty() ) 18 | cout << S.pop(); 19 | return 0; 20 | } -------------------------------------------------------------------------------- /booknotes/demo/a_evaluate.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | using namespace std; 6 | const char pri[N_][] = {}; 7 | //逆波兰转换 8 | float evaluate(char * s, char * & RPN) { 9 | Stack opnd; 10 | Stack optr; 11 | optr.push('\0'); 12 | while (!optr.empty()) { 13 | if (isdigit(*S)) 14 | readNumber(S, opnd); 15 | else { 16 | switch( orderBetween(optr.top(), *S) ) { 17 | case '<': 18 | optr.push(*S); 19 | S++; 20 | break; 21 | case '=': 22 | optr.pop(); 23 | S++; 24 | break; 25 | case '>': { 26 | char op = optr.pop(); 27 | if ('!' == op) //一元运算符 28 | opnd.push( calcu(op, opnd.pop()) ); 29 | else { //二元运算符 30 | float pOpnd2 = opnd.pop(); //操作数 31 | float pOpnd1 = opnd.pop(); 32 | opnd.push( calcu(pOpnd1, op, pOpnd2) ); //运算并回收 33 | } 34 | break; 35 | } 36 | } 37 | } 38 | } 39 | return opnd.pop(); 40 | } -------------------------------------------------------------------------------- /booknotes/demo/a_fib.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | //递归 3 | int fib(int n){ 4 | return (2 > n) ? n : fib(n-1) + fib(n-2); 5 | } 6 | //迭代 7 | int fib2(int n){ 8 | int f = 0, g = 1; 9 | while(0 < n--){ 10 | g = g + f; 11 | f = g - f; 12 | } 13 | return g; 14 | } 15 | int main(void){ 16 | // std:: cout << fib(64) << std:: endl; 17 | std:: cout << fib2(64) << std:: endl; 18 | return 0; 19 | } -------------------------------------------------------------------------------- /booknotes/demo/a_hailstone.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Hailstone问题 3 | */ 4 | #include 5 | using namespace std; 6 | int hailstone(int n) { 7 | int length = 1; 8 | while(1 < n){ 9 | n%2==0 ? n/=2 : n=3*n+1; 10 | length++; 11 | } 12 | return length; 13 | } 14 | int main(){ 15 | int n; 16 | cin >> n; 17 | cout << hailstone(n) << endl; 18 | return 0; 19 | } 20 | -------------------------------------------------------------------------------- /booknotes/demo/a_paren.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | bool paren(const char exp[], int lo, int hi) { 5 | Stack S; 6 | for (int i = lo; i < hi; i++) 7 | if( exp[i] == '(' ) 8 | S.push(exp[i]); 9 | else if( !S.empty() ) 10 | S.pop(); 11 | else 12 | return false; 13 | return S.empty(); 14 | } 15 | int main(void) { 16 | char exp[20] = { '(' }; 17 | paren(exp, 0, 20); 18 | return 0; 19 | } -------------------------------------------------------------------------------- /booknotes/demo/a_sum.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int SumI(int A[], int n){ 4 | int sum = 0; 5 | for (int i = 0; i < n; ++i) 6 | { 7 | sum += A[i]; 8 | } 9 | return sum; 10 | } //迭代 11 | int SumJ(int A[], int n){ 12 | return (n < 1) ? 0 : SumJ(A, n-1) + A[n+1] ; 13 | } //递归 14 | int sum(int A[], int lo, int hi){ 15 | if(lo == hi) return A[lo]; 16 | int mi = (lo+hi) >> 1; 17 | return sum(A, lo, mi) + sum(A, mi + 1, hi); 18 | }//二分递归 19 | int main(){ 20 | int A[10] = {1,2,3,4,5,6,7,7,8,9}; 21 | // cout << SumI(a, 10) << endl; 22 | // cout << SumJ(A, 10) << endl; 23 | cout << sum(A, 0, 9); 24 | return 0; 25 | } -------------------------------------------------------------------------------- /booknotes/demo/a_vector.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | 5 | int main(void){ 6 | vector v(10, 0); 7 | return 0; 8 | } -------------------------------------------------------------------------------- /booknotes/demo/fib.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/suoyuesmile/suo-blog/6068b6934e0bcae9b189fcefdc6a6d3752295a29/booknotes/demo/fib.exe -------------------------------------------------------------------------------- /booknotes/demo/hailstone.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/suoyuesmile/suo-blog/6068b6934e0bcae9b189fcefdc6a6d3752295a29/booknotes/demo/hailstone.exe -------------------------------------------------------------------------------- /booknotes/demo/sort.cpp: -------------------------------------------------------------------------------- 1 | template void Verctor::quickSort( Rank lo, Rank hi) { 2 | if( hi - lo < 2) return 0; //平凡解 3 | Rank mi = partition( lo, hi-1 ); //先构造轴点 4 | quickSort(lo, mi); //前缀排序 5 | quickSort(mi+1, hi); //后缀排序 6 | } 7 | template Rank Vector::partition( Rank lo, Rank hi) { 8 | swap( _elem[ lo ], _elem[ lo + rand() % ( hi - lo + 1 ) ] );//随机交换 9 | T pivot = _elem[ lo ]; 10 | int mi = lo; 11 | for ( int k = lo + 1; k <= hi; k++ ) //自左向右考查每个[k] 12 | if( _elem[ k ] < pivot ) //若k小于轴点,则将其与[mi]交换,L向右扩展 13 | swap( _elem[ ++mi ], _elem[ k ]); 14 | swap( _elem[ lo ], _elem[ mi ] ); //候选抽点归位 15 | return mi;//返回轴点的秩 16 | } -------------------------------------------------------------------------------- /booknotes/demo/test.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/suoyuesmile/suo-blog/6068b6934e0bcae9b189fcefdc6a6d3752295a29/booknotes/demo/test.exe -------------------------------------------------------------------------------- /booknotes/proqueue.md: -------------------------------------------------------------------------------- 1 | # 优先级队列 2 | ### 需求动机 3 | - 门诊的队列 4 | - 电脑中cup的调度 5 | 6 | ### 实现 7 | - 接口 8 | ``` 9 | template struct PQ{ 10 | virtual void insert(T) = 0; //按优先级插入词条 11 | virtual T getMax() = 0; //取出优先级最高的词条 12 | virtual T delMax() = 0; //删除优先级最高的词条 13 | }; //与其说是PQ是数据结构,不如说是ADT。根据不同的实现方式,适用于不同的场合 14 | ``` 15 | - 实现: 16 | - - 向量,列表都不能使三个接口效率达到最 17 | - - 借助BBST(AVL,Splay,Red-black)均满足O(logn 18 | - - 但是BBST的功能超过了PQ的需求 19 | - - 只需查找极值元,不必维护全序,只需维护偏序即可 20 | 21 | ### 完全二叉堆(Complate Binary heap) 22 | - 逻辑:完全二叉树(Complete Binary Tree) 23 | - 物理:向量(vertor) 24 | - 对应:依层次遍历彼此对应 25 | 26 | ``` 27 | #define Parent(i) ( (i-1) >> 1 ) 28 | #define LChild(i) ( 1 + ( ( i ) << 1 ) ) //奇数 29 | #define RChild(i) ( ( 1 + (i) ) << 1 ) //偶数 30 | ``` 31 | - 实现 32 | 33 | ``` 34 | template class PQ_ComplHeap : public PQ , public Vector { 35 | protected: 36 | Rank percolateDown( Rank n, Rank i); //下滤 37 | Rank percolateUp( Rank i ); // 上滤 38 | void heapify( Rank n); //Floyd建堆算法 39 | public: 40 | PQ_ComplHead( T* A, Rank n) { copyFrom(A, 0, n); heapify(n); } 41 | //批量构造 42 | void insert(T); //按照比较器确定的优先级次序,插入词条 43 | T getMax() { return _elem[0]; } 44 | T delMax(); 45 | } 46 | ``` 47 | - 堆序性:H[i] <= H[ Parent(i) ] 故H[0]为最大元素 48 | 49 | ### 堆排序 50 | ### 左式堆 51 | -------------------------------------------------------------------------------- /booknotes/string.md: -------------------------------------------------------------------------------- 1 | # 串 2 | ### ADT 3 | ### 串匹配 4 | ### 蛮力匹配 5 | ### KMP算法 6 | ### BM_BC算法 7 | ### Krap-Rabin算法 -------------------------------------------------------------------------------- /booknotes/sum.md: -------------------------------------------------------------------------------- 1 | # 归纳整理 2 | ### 数据结构(Data Structure) 3 | - 数组(Array):物理上紧邻的定长线性序列(元素为数) 4 | - 向量(Vector):物理上紧邻的一组不定长线性序列(元素不限) 5 | - 列表(List):逻辑上紧邻的一组线性序列 6 | - 栈(Stack):受限的列表(一端出入) 7 | - 队列(Queue):受限的列表(一端出一端入) 8 | - 树(Tree):成树结构的半线性序列 9 | - 图(Graph):成图结构的非线性序列 10 | 11 | ### STL序列容器(Sequence Contains) 12 | - 定长数组(Array) 13 | - 向量(Vector) 14 | - 列表(双向链表)(List) 15 | - - 单链表(sList):非标准STL 16 | - 双端队列(Deque) 17 | - - 栈(Stack) 18 | - - 队列(Queue) 19 | 20 | ### STL关联容器(Associative Contains) 21 | - 红黑树(Red-Black Tree) 22 | - - 集合(Set) 23 | - - 映射(Map) 24 | - - 扩展集合(mutiMap) 25 | - - 扩展映射(mutiSet) 26 | - 哈希表(HashTable) 27 | - - 哈希集合(HashSet) 28 | - - 哈希映射(HashMap) 29 | - - 哈希集合扩展(mutiHashSet) 30 | - - 哈希映射扩展(mutiHashMap) 31 | 32 | ### 排序查找搜索 33 | - 排序(Sort) 34 | - - 起泡排序 35 | - - 选择排序 36 | - - 归并排序 37 | - - 插入排序 38 | - - 堆排序 39 | - - 桶排序 40 | - - 基数排序 41 | - - 快速排序 42 | - - 希尔排序 43 | - 查找(Find) 44 | - - 扫描查找 45 | - - 二分查找 46 | - - fib查找 47 | - 搜索(Search) 48 | - - 广度搜索 49 | - - 深度搜索 -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "suo-blog", 3 | "version": "1.0.0", 4 | "main": "index.js", 5 | "repository": "https://github.com/suoyuesmile/suo-blog.git", 6 | "author": "shaosuo ", 7 | "license": "MIT", 8 | "scripts": { 9 | "dev": "tsc --build tsconfig.json" 10 | }, 11 | "dependencies": { 12 | "@babel/core": "^7.12.3", 13 | "@babel/preset-env": "^7.12.1", 14 | "@babel/traverse": "^7.12.1", 15 | "babel": "^6.23.0", 16 | "babel-core": "^6.26.3", 17 | "babylon": "^6.18.0", 18 | "crypto-js": "^4.0.0", 19 | "formidable": "^1.2.2", 20 | "koa": "^2.12.0", 21 | "ky": "^0.20.0", 22 | "node-forge": "^0.9.1", 23 | "request": "^2.88.2", 24 | "ts-node": "^8.9.1", 25 | "typescript": "^3.8.3" 26 | }, 27 | "devDependencies": { 28 | "babel-preset-env": "^1.7.0" 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /public/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/suoyuesmile/suo-blog/6068b6934e0bcae9b189fcefdc6a6d3752295a29/public/.DS_Store -------------------------------------------------------------------------------- /public/html/demo-box-model.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 30 | 31 | 32 |
33 |
34 | 35 | 36 | -------------------------------------------------------------------------------- /public/html/demo-display.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 |
10 | 11 |

12 | 13 |


14 | 15 |
      16 | 17 |
      18 | 19 |
      20 | 21 |
      22 | 23 |
      24 | 25 | 26 | 27 |
      28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | -------------------------------------------------------------------------------- /public/html/demo-float.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 11 | 12 | 13 | Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus imperdiet, nulla et dictum interdum, nisi lorem egestas odio, vitae scelerisque enim ligula venenatis dolor. Maecenas nisl est, ultrices nec congue eget, auctor vitae massa 14 | 15 | 16 | -------------------------------------------------------------------------------- /public/html/demo-position.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 36 | } 37 | 38 | 39 |
      40 |
      41 |
      42 |
      43 |
      44 | 45 | 46 | 47 | -------------------------------------------------------------------------------- /public/html/layout.css: -------------------------------------------------------------------------------- 1 | .main { 2 | width: 100px; 3 | margin: 0 auto; 4 | } -------------------------------------------------------------------------------- /public/images/h500001001.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/suoyuesmile/suo-blog/6068b6934e0bcae9b189fcefdc6a6d3752295a29/public/images/h500001001.jpg -------------------------------------------------------------------------------- /public/images/h500001002.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/suoyuesmile/suo-blog/6068b6934e0bcae9b189fcefdc6a6d3752295a29/public/images/h500001002.jpg -------------------------------------------------------------------------------- /public/images/h500001003.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/suoyuesmile/suo-blog/6068b6934e0bcae9b189fcefdc6a6d3752295a29/public/images/h500001003.jpg -------------------------------------------------------------------------------- /public/images/h500001004.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/suoyuesmile/suo-blog/6068b6934e0bcae9b189fcefdc6a6d3752295a29/public/images/h500001004.jpg -------------------------------------------------------------------------------- /public/images/h500001005.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/suoyuesmile/suo-blog/6068b6934e0bcae9b189fcefdc6a6d3752295a29/public/images/h500001005.jpg -------------------------------------------------------------------------------- /public/images/h500001006.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/suoyuesmile/suo-blog/6068b6934e0bcae9b189fcefdc6a6d3752295a29/public/images/h500001006.jpg -------------------------------------------------------------------------------- /public/images/h500001007.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/suoyuesmile/suo-blog/6068b6934e0bcae9b189fcefdc6a6d3752295a29/public/images/h500001007.jpg -------------------------------------------------------------------------------- /public/images/h500001008.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/suoyuesmile/suo-blog/6068b6934e0bcae9b189fcefdc6a6d3752295a29/public/images/h500001008.jpg -------------------------------------------------------------------------------- /public/images/h500001009.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/suoyuesmile/suo-blog/6068b6934e0bcae9b189fcefdc6a6d3752295a29/public/images/h500001009.jpg -------------------------------------------------------------------------------- /public/images/h50001001.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/suoyuesmile/suo-blog/6068b6934e0bcae9b189fcefdc6a6d3752295a29/public/images/h50001001.jpg -------------------------------------------------------------------------------- /public/images/h50001002.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/suoyuesmile/suo-blog/6068b6934e0bcae9b189fcefdc6a6d3752295a29/public/images/h50001002.jpg -------------------------------------------------------------------------------- /public/images/h50001003.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/suoyuesmile/suo-blog/6068b6934e0bcae9b189fcefdc6a6d3752295a29/public/images/h50001003.jpg -------------------------------------------------------------------------------- /public/images/h50001004.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/suoyuesmile/suo-blog/6068b6934e0bcae9b189fcefdc6a6d3752295a29/public/images/h50001004.jpg -------------------------------------------------------------------------------- /public/images/h50001005.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/suoyuesmile/suo-blog/6068b6934e0bcae9b189fcefdc6a6d3752295a29/public/images/h50001005.jpg -------------------------------------------------------------------------------- /public/images/h50001006.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/suoyuesmile/suo-blog/6068b6934e0bcae9b189fcefdc6a6d3752295a29/public/images/h50001006.jpg -------------------------------------------------------------------------------- /public/images/h50001007.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/suoyuesmile/suo-blog/6068b6934e0bcae9b189fcefdc6a6d3752295a29/public/images/h50001007.jpg -------------------------------------------------------------------------------- /public/images/qian.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/suoyuesmile/suo-blog/6068b6934e0bcae9b189fcefdc6a6d3752295a29/public/images/qian.jpg -------------------------------------------------------------------------------- /public/images/weixin.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/suoyuesmile/suo-blog/6068b6934e0bcae9b189fcefdc6a6d3752295a29/public/images/weixin.png -------------------------------------------------------------------------------- /src/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/suoyuesmile/suo-blog/6068b6934e0bcae9b189fcefdc6a6d3752295a29/src/.DS_Store -------------------------------------------------------------------------------- /src/README.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/suoyuesmile/suo-blog/6068b6934e0bcae9b189fcefdc6a6d3752295a29/src/README.md -------------------------------------------------------------------------------- /src/algorithm/array/insert.js: -------------------------------------------------------------------------------- 1 | /** 2 | * insert el into array 3 | * @param {Array} arr 4 | * @param {Number} targetIndex 5 | * @param {Number} target 6 | * @return null 7 | */ 8 | function insert(arr, targetIndex, target) { 9 | var i = arr.length 10 | while (i-- > targetIndex) { 11 | arr[i + 1] = arr[i] 12 | } 13 | arr[targetIndex] = target 14 | return arr 15 | } 16 | 17 | console.log(insert([1, 2, 4, 5], 4, 3)) 18 | -------------------------------------------------------------------------------- /src/algorithm/array/searchInsert.js: -------------------------------------------------------------------------------- 1 | /* 2 | * @lc app=leetcode.cn id=35 lang=javascript 3 | * 4 | * [35] 搜索插入位置 5 | * 6 | * https://leetcode-cn.com/problems/search-insert-position/description/ 7 | * 8 | * algorithms 9 | * Easy (44.77%) 10 | * Likes: 398 11 | * Dislikes: 0 12 | * Total Accepted: 104K 13 | * Total Submissions: 232.2K 14 | * Testcase Example: '[1,3,5,6]\n5' 15 | * 16 | * 给定一个排序数组和一个目标值,在数组中找到目标值,并返回其索引。如果目标值不存在于数组中,返回它将会被按顺序插入的位置。 17 | * 18 | * 你可以假设数组中无重复元素。 19 | * 20 | * 示例 1: 21 | * 22 | * 输入: [1,3,5,6], 5 23 | * 输出: 2 24 | * 25 | * 26 | * 示例 2: 27 | * 28 | * 输入: [1,3,5,6], 2 29 | * 输出: 1 30 | * 31 | * 32 | * 示例 3: 33 | * 34 | * 输入: [1,3,5,6], 7 35 | * 输出: 4 36 | * 37 | * 38 | * 示例 4: 39 | * 40 | * 输入: [1,3,5,6], 0 41 | * 输出: 0 42 | * 43 | * 44 | */ 45 | 46 | // @lc code=start 47 | /** 48 | * @param {number[]} nums 49 | * @param {number} target 50 | * @return {number} 51 | */ 52 | var searchInsert = function(nums, target) { 53 | var hi = nums.length - 1, 54 | lo = 0 55 | 56 | // 2.迭代,换界 57 | while (hi >= lo) { 58 | var mi = (hi - lo) >>> 1 59 | 60 | if (target < nums[mi]) { 61 | hi = mi - 1 62 | } else if (nums[mi] < target) { 63 | lo = mi + 1 64 | } else { 65 | return mi 66 | } 67 | } 68 | } 69 | 70 | searchInsert([1, 2, 4, 5], 3) 71 | // @lc code=end 72 | -------------------------------------------------------------------------------- /src/algorithm/search/binsearch.js: -------------------------------------------------------------------------------- 1 | var arr = [1, 3, 5, 6] 2 | 3 | var target = 5 4 | 5 | function binSearch(target, arr) { 6 | // 1.定界 7 | var hi = arr.length - 1, 8 | lo = 0 9 | 10 | // 2.迭代,换界 11 | while (hi - lo >= 1) { 12 | var mi = Math.floor((hi + lo) / 2) 13 | if (target < arr[mi]) { 14 | hi = mi 15 | } else if (arr[mi] < target) { 16 | lo = mi 17 | } else { 18 | return mi 19 | } 20 | } 21 | } 22 | 23 | console.log(binSearch(target, arr)) 24 | -------------------------------------------------------------------------------- /src/algorithm/sort/bubblesort.js: -------------------------------------------------------------------------------- 1 | /** 2 | * 冒泡排序 3 | * bubblesort 4 | * @param {Array} Array 5 | * @return {Array} 6 | */ 7 | 8 | function bubble(arr) { 9 | for (let i = 0; i < arr.length; i++) { 10 | for (let j = 0; j < arr.length - i; j++) { 11 | var temp 12 | if (arr[j + 1] > arr[j]) { 13 | temp = arr[j + 1] 14 | arr[j + 1] = arr[j] 15 | arr[j] = temp 16 | } 17 | } 18 | } 19 | return arr 20 | } 21 | 22 | // 为什么 j 到 arr.length 就可以了 23 | 24 | // 因为 i 到 arr.length 已经复位了 25 | 26 | // 复杂度 O(n2) 不稳定排序 27 | -------------------------------------------------------------------------------- /src/algorithm/sort/quicksort.js: -------------------------------------------------------------------------------- 1 | var originArr = [2, 3, 5, 7, 1, 4, 6, 9, 8, 0] 2 | 3 | var quickSort = function(arr) { 4 | var pivotIndex, // 轴点索引 5 | pivot, // 轴点 6 | leftArr = [], // 轴点左边数组 7 | rightArr = [], // 轴点右边数组 8 | i // for循环索引 9 | 10 | // 1.平凡解 11 | if (arr.length <= 1) { 12 | return arr 13 | } 14 | 15 | // 2.确定轴点 16 | pivotIndex = Math.floor(arr.length / 2) 17 | pivot = arr.splice(pivot, 1)[0] 18 | 19 | // 3.分组 20 | for (i = 0; i < arr.length; i++) { 21 | if (arr[i] < pivot) { 22 | leftArr.push(arr[i]) 23 | } else { 24 | rightArr.push(arr[i]) 25 | } 26 | } 27 | 28 | // 4.递归 29 | return quickSort(leftArr).concat(pivot, quickSort(rightArr)) 30 | } 31 | 32 | console.log(quickSort(originArr)) 33 | 34 | // 最差:O(n2) 35 | // 平均:O(nlgn) 36 | -------------------------------------------------------------------------------- /src/algorithm/string/repeat.js: -------------------------------------------------------------------------------- 1 | function repeat(o, n) { 2 | if (n == 1) 3 | return o 4 | let half = Math.ceil(n / 2); 5 | return repeat(o, half) + repeat(o, n - half) 6 | } 7 | 8 | console.log(repeat('abc', 5)); 9 | 10 | // 输出连续n个字符串 11 | -------------------------------------------------------------------------------- /src/cryto/sha256.js: -------------------------------------------------------------------------------- 1 | const crypto = require('crypto-js/sha256'); 2 | const Base64 = require('crypto-js/enc-base64'); 3 | 4 | const jsonData = {reqSerialNum: "2020040318241452", agentId: "1000000000000002", memberId: "310000016002378725", photoType: "01" }; 5 | // jsonData 6 | console.log(JSON.stringify(jsonData) + 'chinapnr'); 7 | // checkValue 8 | console.log(crypto('{"agentId":"310000015002423502","memberId":"310000016002426182","photoType":"06","reqSerialNum":"1211"}' + 'chinapnr').toString()); 9 | // console.log(crypto({"agentId":"310000015002423502","memberId":310000016002426182,"photoType":"06","reqSerialNum":1211}chinapnr, 'chinanpr').toString()); 10 | -------------------------------------------------------------------------------- /src/css/box-model.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | box-model 8 | 35 | 36 | 37 |
      38 |
      1
      39 |
      2
      40 |
      3
      41 |
      42 | 43 | 44 | -------------------------------------------------------------------------------- /src/css/center.html: -------------------------------------------------------------------------------- 1 | 2 |
      水平居中1
      3 |
      水平居中2
      4 |
      5 |
      水平居中3
      6 |
      7 | 8 | 9 | 38 | -------------------------------------------------------------------------------- /src/css/float.html: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/suoyuesmile/suo-blog/6068b6934e0bcae9b189fcefdc6a6d3752295a29/src/css/float.html -------------------------------------------------------------------------------- /src/css/layout.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 14 | 15 | 16 |
      17 | 33 |
      34 |
      35 |
      36 |
      37 |
      38 |
      39 | 40 | 41 | -------------------------------------------------------------------------------- /src/css/three-layout.html: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/suoyuesmile/suo-blog/6068b6934e0bcae9b189fcefdc6a6d3752295a29/src/css/three-layout.html -------------------------------------------------------------------------------- /src/css/two-layout.html: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/suoyuesmile/suo-blog/6068b6934e0bcae9b189fcefdc6a6d3752295a29/src/css/two-layout.html -------------------------------------------------------------------------------- /src/css/var.html: -------------------------------------------------------------------------------- 1 | 2 |
      123
      3 | 4 | 5 | -------------------------------------------------------------------------------- /src/data-structure/linklist-circle.js: -------------------------------------------------------------------------------- 1 | // -------------------------------------------------------------------------------- /src/data-structure/linklist-curd.js: -------------------------------------------------------------------------------- 1 | const NodeList = function (val) { 2 | this.val = val === undefined ? 0 : val; 3 | this.next = null; 4 | } 5 | 6 | // 头插法(新结点插在头部) 7 | const createByHead = function (nums) { 8 | let p = null; 9 | let head = new NodeList(null); 10 | 11 | for (const num of nums) { 12 | p = new NodeList(num); 13 | p.next = head.next; 14 | head.next = p; 15 | } 16 | 17 | return head; 18 | } 19 | 20 | // 尾插法(新结点插在尾部) 21 | const createByTail = function (nums) { 22 | let head = new NodeList(null); 23 | let p = head; 24 | 25 | for (const num of nums) { 26 | s = new NodeList(num); 27 | p.next = s; 28 | p = p.next; 29 | } 30 | return head; 31 | } 32 | 33 | // 重置为空 34 | const deleteAll = function (l1) { 35 | let p = l1; 36 | while(p) { 37 | q = p; 38 | delete p.next; 39 | p = q.next; 40 | } 41 | } 42 | 43 | // const l1 = createByHead([1, 3, 5, 6, 7]); 44 | // const l2 = createByTail([1, 3, 5, 6, 7]); 45 | // console.log(JSON.stringify(l1)); 46 | // console.log(JSON.stringify(l2)); 47 | // deleteAll(l1); 48 | // console.log(JSON.stringify(l1)); 49 | 50 | // exports.default = { 51 | // NodeList, 52 | // createByHead, 53 | // createByTail, 54 | // deleteAll 55 | // }; 56 | 57 | exports.NodeList = NodeList; 58 | exports.createByTail = createByTail; 59 | 60 | 61 | -------------------------------------------------------------------------------- /src/data-structure/list.js: -------------------------------------------------------------------------------- 1 | // 单链表 2 | function ListNode(val) { 3 | this.val = val 4 | this.next = null 5 | } 6 | 7 | var l1 = new ListNode(1) 8 | var node2 = new ListNode(2) 9 | l1.next = node2 10 | 11 | console.log(l1) 12 | console.log(l1.next) 13 | console.log(l1.next.val) 14 | console.log(l1.next.next) 15 | 16 | abc 17 | abc 18 | abc 19 | abc 20 | abc 21 | abc 22 | abc 23 | abc 24 | abc 25 | abc 26 | abc 27 | abc 28 | abc 29 | abc 30 | abc 31 | abc 32 | abc 33 | abc 34 | abc 35 | abc 36 | -------------------------------------------------------------------------------- /src/javascript/array.js: -------------------------------------------------------------------------------- 1 | const arr = [ 1, 3, 5, 7, 9]; 2 | const arr2 = [1, [2, 3], [4, 5, 6, 7, [8, 9]]]; 3 | 4 | 5 | const result1 = arr.reduce((prev, current) => prev + current); 6 | 7 | // 递归 8 | function flat(array) { 9 | return array.reduce((prev, current) => prev.concat(Array.isArray(current) ? flat(current) : current), []); 10 | } 11 | 12 | console.log(flat(arr2)); 13 | 14 | console.log(result1); 15 | 16 | 17 | -------------------------------------------------------------------------------- /src/javascript/async_sync.js: -------------------------------------------------------------------------------- 1 | setTimeout(() => { 2 | console.log(1) 3 | }, 1000) 4 | 5 | var a = new Promise(() => { 6 | console.log(2) 7 | b = new Promise(() => { 8 | console.log(3) 9 | }) 10 | }) 11 | 12 | setTimeout(() => { 13 | console.log(4) 14 | }) 15 | 16 | // 2 3 4 1 17 | -------------------------------------------------------------------------------- /src/javascript/block-scope.js: -------------------------------------------------------------------------------- 1 | // 块级作用域 2 | for (var index = 0; index < 10; index++) { 3 | console.log(index) 4 | } 5 | console.log(index) 6 | // 会影响函数作用域和全局作用域 7 | 8 | // with 9 | // try/catch 10 | 11 | try { 12 | undefined() 13 | } catch (err) { 14 | // console.log(1, err) 15 | } 16 | 17 | // console.log(err) 18 | 19 | // let 改变现状 增强了块级作用域,不会被变量提升 20 | -------------------------------------------------------------------------------- /src/javascript/callback.js: -------------------------------------------------------------------------------- 1 | // callback function 2 | function A() { 3 | console.log('I am callback') 4 | } 5 | 6 | function B(callback) { 7 | console.log('I am B, I do something!') 8 | callback() 9 | } 10 | 11 | B(A) 12 | 13 | function C(callback) { 14 | console.log('I am B, I do something!') 15 | callback() 16 | } 17 | 18 | C(function () { 19 | console.log('I am callback!') 20 | }) -------------------------------------------------------------------------------- /src/javascript/class.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/suoyuesmile/suo-blog/6068b6934e0bcae9b189fcefdc6a6d3752295a29/src/javascript/class.js -------------------------------------------------------------------------------- /src/javascript/class/construct.js: -------------------------------------------------------------------------------- 1 | function FakeClass(val) { 2 | this.property = val; 3 | this.someFunction = function() { 4 | console.log(1); 5 | } 6 | } 7 | FakeClass.prototype.a = 2; 8 | 9 | FakeClass.prototype.b = function() { 10 | console.log(2) 11 | } 12 | 13 | const obj = new FakeClass(2); 14 | 15 | console.log(FakeClass); -------------------------------------------------------------------------------- /src/javascript/closure/closure-circle.js: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /src/javascript/closure/proxy.js: -------------------------------------------------------------------------------- 1 | function dos() { 2 | var pipe = function (value) { 3 | var funcStack = []; 4 | var oproxy = new Proxy({}, { 5 | get: function (pipeObject, fnName) { 6 | if (fnName === 'get') { 7 | return funcStack.reduce(function (val, fn) { 8 | console.log(1); 9 | return fn(val); 10 | }, value); 11 | } 12 | // console.log(global.double); 13 | funcStack.push(global[fnName]); 14 | return oproxy; 15 | } 16 | }); 17 | 18 | return oproxy; 19 | } 20 | 21 | global.double = n => n * 2; 22 | global.pow = n => n * n; 23 | global.reverseInt = n => n.toString().split("").reverse().join("") | 0; 24 | 25 | // pipe(3).double.pow.reverseInt.get; // 63 26 | 27 | console.log(pipe(3).double.pow.reverseInt.get); 28 | } 29 | 30 | dos(); 31 | console.log(1, 2); 32 | -------------------------------------------------------------------------------- /src/javascript/code/huiwen-longest-str.js: -------------------------------------------------------------------------------- 1 | // Input babad 2 | // Output bab 3 | 4 | // isHuiwen 5 | // ab 6 | 7 | function solve(s) { 8 | const len = s.length; 9 | const middle = len / 2; 10 | 11 | let i = 0, j = len -1; 12 | 13 | 14 | while (i < middle + 1 && j >= middle - 1) { 15 | if (s[i] !== s[j]) { 16 | return false; 17 | } 18 | i++; 19 | j--; 20 | } 21 | 22 | return true; 23 | } 24 | 25 | console.log(solve('abac')); -------------------------------------------------------------------------------- /src/javascript/code/is-huiwen-num.js: -------------------------------------------------------------------------------- 1 | // Input: 121 2 | // OutPut ture 3 | 4 | // Input: -121 5 | // OutPut false 6 | 7 | // Input: 100 8 | // OutPut false 9 | 10 | // 1 2 1 11 | 12 | function solve(x) { 13 | let tmp = x; 14 | const stack = []; 15 | 16 | if (x < 0) { 17 | return false; 18 | } 19 | 20 | while(tmp) { 21 | stack.push(tmp % 10); 22 | tmp = Math.floor(tmp / 10); 23 | } 24 | 25 | tmp = x; 26 | while (tmp) { 27 | if (stack.pop() !== Math.floor(tmp % 10)) { 28 | return false; 29 | } 30 | tmp = Math.floor(tmp / 10) 31 | } 32 | return true; 33 | } 34 | 35 | console.log(solve(101)); 36 | -------------------------------------------------------------------------------- /src/javascript/code/is-huiwen-string.js: -------------------------------------------------------------------------------- 1 | // Input babad 2 | // Output bab 3 | 4 | // isHuiwen 5 | // ab 6 | 7 | function solve(s) { 8 | const len = s.length; 9 | const middle = len / 2; 10 | 11 | let i = 0, j = len - 1; 12 | 13 | 14 | while (i < middle + 1 && j >= middle - 1) { 15 | if (s[i] !== s[j]) { 16 | return false; 17 | } 18 | i++; 19 | j--; 20 | } 21 | 22 | return true; 23 | } 24 | 25 | console.log(solve('abac')); -------------------------------------------------------------------------------- /src/javascript/code/longest-asc-str.js: -------------------------------------------------------------------------------- 1 | function longestAseStr() {} 2 | 3 | console.log(longestAseStr([1, 3, 2, 5, 7])); 4 | -------------------------------------------------------------------------------- /src/javascript/code/longest-norepeat-str.js: -------------------------------------------------------------------------------- 1 | // Input abcadc 2 | 3 | // Output 4(bcad) 4 | 5 | // 1 6 | // abc -> set 7 | // a 8 | 9 | // 2 10 | // '' 11 | 12 | // 3 13 | // abc 14 | 15 | 16 | function solve(s) { 17 | const len = s.length; 18 | const tmpSet = new Set(); 19 | let i = 0, maxlen = 0; 20 | 21 | while(i < len) { 22 | if (!tmpSet.has(s[i]) && i === len - 1) { 23 | maxlen = Math.max(tmpSet.size, maxlen); 24 | } 25 | 26 | if (!tmpSet.has(s[i])) { 27 | tmpSet.add(s[i]); 28 | } else { 29 | maxlen = Math.max(tmpSet.size, maxlen); 30 | i = i - tmpSet.size; 31 | tmpSet.clear(); 32 | } 33 | 34 | i++; 35 | } 36 | 37 | return maxlen; 38 | } -------------------------------------------------------------------------------- /src/javascript/code/merge-two-array.js: -------------------------------------------------------------------------------- 1 | function mergeTwoArray(l1, l2) { 2 | const len1 = l1.length, len2 = l2.length; 3 | const newArr = []; 4 | let i = 0, j = 0; 5 | 6 | 7 | while(i < len1 || j < len2) { 8 | if (l1[i] < l2[j]) { 9 | newArr.push(l1[i]); 10 | i++ 11 | } else { 12 | newArr.push(l2[j]); 13 | j++ 14 | } 15 | } 16 | 17 | return newArr; 18 | } 19 | 20 | console.log(mergeTwoArray([1, 3, 8], [2, 4, 9])); 21 | 22 | // [1, 3, 8] 23 | // [2, 4, 9] 24 | // -------------------------------------------------------------------------------- /src/javascript/code/two-nums-2.js: -------------------------------------------------------------------------------- 1 | function twoNums(nums, target) { 2 | const map = new Map(); 3 | const length = nums.length; 4 | 5 | for (let i = 1; i < length; i++) { 6 | map.set(nums[i], i); 7 | } 8 | 9 | for (let i = 0; i < length; i++) { 10 | let pattern = target - nums[i]; 11 | const patternkey = map.get(pattern); 12 | if (patternkey && i !== patternkey) { 13 | return [i, patternkey]; 14 | } 15 | 16 | } 17 | 18 | throw new Error('没有找到'); 19 | } 20 | 21 | console.log(twoNums([1, 5, 3, 7], 10)); -------------------------------------------------------------------------------- /src/javascript/code/two-nums-add.js: -------------------------------------------------------------------------------- 1 | 2 | 3 | function twoNumsAdd(l1, l2) { 4 | 5 | } -------------------------------------------------------------------------------- /src/javascript/code/two-nums.js: -------------------------------------------------------------------------------- 1 | function twoNums(nums, target) { 2 | const set = new Set(nums); 3 | for (const num of nums) { 4 | const pattern = target - num; 5 | if (set.has(pattern)) { 6 | return [num, pattern] 7 | } 8 | } 9 | } 10 | 11 | console.log(twoNums([1, 3, 5, 7, 9, 10], 19)); 12 | 13 | -------------------------------------------------------------------------------- /src/javascript/code/valid-parent.js: -------------------------------------------------------------------------------- 1 | // [({}[]) 2 | 3 | 4 | 5 | function validParent(s) { 6 | const len = s.length; 7 | const tmpStack = []; 8 | const patternMap = new Map(); 9 | patternMap.set('{', '}'); 10 | patternMap.set('(', ')'); 11 | patternMap.set('[', ']'); 12 | 13 | let i = 0; 14 | while(i < len) { 15 | if (patternMap.has(s[i])) { 16 | tmpStack.push(s[i]); 17 | } else { 18 | if (patternMap.get(tmpStack.pop()) !== s[i]) { 19 | return false 20 | } 21 | } 22 | i++ 23 | } 24 | 25 | return tmpStack.length === 0; 26 | 27 | } 28 | 29 | console.log(validParent('()')); 30 | -------------------------------------------------------------------------------- /src/javascript/curry.js: -------------------------------------------------------------------------------- 1 | // 函数柯里化 2 | function curry(fn, len = fn.length) { 3 | return _curry.call(this, fn, len) 4 | } 5 | 6 | function _curry(fn, len, ...args) { 7 | return function(...params) { 8 | let _args = [...args, ...params] 9 | if (_args.length >= len) { 10 | return fn.apply(this, _args) 11 | } else { 12 | return _curry.call(this, fn, len, ..._args) 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/javascript/debounce.js: -------------------------------------------------------------------------------- 1 | /** 2 | * 防抖-任务频繁触发下,只有当任务触发超过指定间隔,任务再次才会触发 3 | */ 4 | function debounce(fn, intervalTime) { 5 | let timer 6 | return function() { 7 | if (timer) { 8 | clearTimeout(timer) 9 | } 10 | setTimeout(() => { 11 | fn.call(this, arguments) 12 | }, intervalTime) 13 | } 14 | } 15 | 16 | function task() { 17 | console.log('ok') 18 | } 19 | 20 | debounce(task, 1000) 21 | -------------------------------------------------------------------------------- /src/javascript/dom.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/suoyuesmile/suo-blog/6068b6934e0bcae9b189fcefdc6a6d3752295a29/src/javascript/dom.js -------------------------------------------------------------------------------- /src/javascript/event-loop.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/suoyuesmile/suo-blog/6068b6934e0bcae9b189fcefdc6a6d3752295a29/src/javascript/event-loop.js -------------------------------------------------------------------------------- /src/javascript/event.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/suoyuesmile/suo-blog/6068b6934e0bcae9b189fcefdc6a6d3752295a29/src/javascript/event.js -------------------------------------------------------------------------------- /src/javascript/flat.js: -------------------------------------------------------------------------------- 1 | // Array.prototype.flat 2 | 3 | const origin = [1, [2, 3], [4, [5, 6], [7, 8, 9]]] 4 | 5 | 6 | function flat(origin) { 7 | let res = [] 8 | for (let i = 0; i < origin.length; i++) { 9 | if (Array.isArray(origin[i])) { 10 | res = res.concat(flat(origin[i])) 11 | } else { 12 | res.push(origin[i]) 13 | } 14 | } 15 | return res 16 | } 17 | 18 | function reduce_flat(origin) { 19 | return origin.reduce((a, b) => { 20 | if (Array.isArray(b)) { 21 | return a.concat(reduce_flat(b)) 22 | } else { 23 | return a.concat(b) 24 | } 25 | }, []) 26 | } 27 | 28 | console.log(reduce_flat(origin)) 29 | console.log(flat(origin)) 30 | -------------------------------------------------------------------------------- /src/javascript/function-scope.js: -------------------------------------------------------------------------------- 1 | // 函数作用域 2 | // 函数的全部变量都可以在整个函数范围内使用及复用 3 | // 使用函数作用域隐藏部分变量和函数-最小暴露原则 4 | 5 | // 规避冲突 6 | // 1.全局命名空间 7 | // 2.模块管理 8 | 9 | var a = 2 10 | 11 | function foo() { 12 | var a = 3 13 | console.log(3) 14 | } 15 | 16 | foo() 17 | 18 | console.log(a) 19 | 20 | // 包装函数缺点 21 | // 1.函数自身污染作用域 22 | // 2.必须显示调用 23 | 24 | // 两种解决方案 25 | // 立即执行函数 26 | ;(function foo() { 27 | var a = 3 28 | console.log(a) 29 | })() 30 | 31 | // 函数声明不可以省略函数名,回调参数等可以 32 | // 缺点1:调试困难 33 | // 2.无法递归 34 | // 3.说明不了作用 35 | 36 | // 立即执行函数表达式 IIFE(immediately invoked function expression) 37 | // 改进版 38 | ;(function() { 39 | var a = 4 40 | console.log(a) 41 | })() 42 | 43 | // 改进全局参数写法 44 | // var a = 2 45 | // ;(function(global) { 46 | // console.log(global.a) 47 | // })(window) 48 | 49 | // 倒置代码运行顺序 50 | // var d = 2 51 | // ;(function IIFE(def) { 52 | // def(window) 53 | // })(function def(globle) { 54 | // console.log(global.d) 55 | // }) 56 | -------------------------------------------------------------------------------- /src/javascript/function-this.js: -------------------------------------------------------------------------------- 1 | function b() { 2 | this.a = 3 3 | } 4 | a = 5 5 | b() 6 | console.log(a) 7 | -------------------------------------------------------------------------------- /src/javascript/hoisting.js: -------------------------------------------------------------------------------- 1 | // 理解变量函数提升 2 | // var a = 1 3 | var a = 2 4 | 5 | console.log(a) 6 | a() 7 | 8 | function a() { 9 | console.log(100) 10 | } 11 | 12 | // ====> 13 | function a() {} 14 | var a 15 | a = 2 16 | 17 | console.log(a) 18 | a() 19 | 20 | // 优先级函数声明提升高于变量声明提升,不会被变量声明提升覆盖,但是会被变量赋值覆盖 21 | // 只有函数声明才会提升,函数字面量不会提升 22 | -------------------------------------------------------------------------------- /src/javascript/implement/apply.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/suoyuesmile/suo-blog/6068b6934e0bcae9b189fcefdc6a6d3752295a29/src/javascript/implement/apply.js -------------------------------------------------------------------------------- /src/javascript/implement/async.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/suoyuesmile/suo-blog/6068b6934e0bcae9b189fcefdc6a6d3752295a29/src/javascript/implement/async.js -------------------------------------------------------------------------------- /src/javascript/implement/bind.js: -------------------------------------------------------------------------------- 1 | Function.prototype.mockBind = function() { 2 | // 使用apply 实现 3 | that = this; 4 | var thatArgs = Array.prototype.slice.call(arguments, 1); 5 | var arg = arguments[0]; 6 | var bound = function() { 7 | var args = thatArgs.concat(Array.prototype.slice.call(arguments)); 8 | return that.apply(this instanceof bound ? this : arg, args); 9 | } 10 | var TmpProto = function() {} 11 | if (that.prototype) { 12 | TmpProto.prototype = that.prototype; 13 | } 14 | bound.prototype = new TmpProto(); 15 | return bound; 16 | } 17 | 18 | var obj = { 19 | a: 'a', 20 | } 21 | 22 | function test(b) { 23 | this.c = 'c'; 24 | console.log(this.a, b); 25 | } 26 | 27 | test.mockBind(obj, 'b')(); 28 | 29 | // var Fn = test.mockBind(obj, 'b'); 30 | // var objFn = new Fn('a'); 31 | // console.log(objFn.c); 32 | 33 | // todo: 理解new的过程 34 | -------------------------------------------------------------------------------- /src/javascript/implement/class.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/suoyuesmile/suo-blog/6068b6934e0bcae9b189fcefdc6a6d3752295a29/src/javascript/implement/class.js -------------------------------------------------------------------------------- /src/javascript/implement/compose.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/suoyuesmile/suo-blog/6068b6934e0bcae9b189fcefdc6a6d3752295a29/src/javascript/implement/compose.js -------------------------------------------------------------------------------- /src/javascript/implement/copy.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/suoyuesmile/suo-blog/6068b6934e0bcae9b189fcefdc6a6d3752295a29/src/javascript/implement/copy.js -------------------------------------------------------------------------------- /src/javascript/implement/inherit.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/suoyuesmile/suo-blog/6068b6934e0bcae9b189fcefdc6a6d3752295a29/src/javascript/implement/inherit.js -------------------------------------------------------------------------------- /src/javascript/implement/new.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/suoyuesmile/suo-blog/6068b6934e0bcae9b189fcefdc6a6d3752295a29/src/javascript/implement/new.js -------------------------------------------------------------------------------- /src/javascript/implement/pipe.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/suoyuesmile/suo-blog/6068b6934e0bcae9b189fcefdc6a6d3752295a29/src/javascript/implement/pipe.js -------------------------------------------------------------------------------- /src/javascript/implement/promise.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/suoyuesmile/suo-blog/6068b6934e0bcae9b189fcefdc6a6d3752295a29/src/javascript/implement/promise.js -------------------------------------------------------------------------------- /src/javascript/implement/reduce.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/suoyuesmile/suo-blog/6068b6934e0bcae9b189fcefdc6a6d3752295a29/src/javascript/implement/reduce.js -------------------------------------------------------------------------------- /src/javascript/implement/sleep.js: -------------------------------------------------------------------------------- 1 | function sleep(ms) { 2 | return new Promise((resolve) => setTimeout(() => resolve(), ms)); 3 | } 4 | 5 | 6 | async function test() { 7 | console.log('start'); 8 | await sleep(3000); 9 | console.log('end'); 10 | } 11 | 12 | test(); 13 | 14 | // 强行占线 while (new Date().getTime() < start + ms); 15 | -------------------------------------------------------------------------------- /src/javascript/inherit.js: -------------------------------------------------------------------------------- 1 | // 如果试图引用对象(实例instance)的某个属性,会首先在对象内部寻找该属性,直至找不到,然后才在该对象的原型(instance.prototype)里去找这个属性. 2 | // 构造函数、原型、实例关系 3 | 4 | /** 5 | * 构造函数 6 | * 构造属性方法 7 | * 原型属性方法 8 | * 实例属性 9 | */ 10 | function Base() { 11 | this.property = true 12 | } 13 | Base.prototype.getProperty = function() { 14 | return this.property 15 | } 16 | 17 | /** 18 | * 原型链继承 19 | * 原理:基类的实例复制给构造函数的原型 20 | * 缺点:多个实例对引用类型的操作会被串改 21 | */ 22 | function PrototypeListInherit() { 23 | this.property = false 24 | } 25 | PrototypeListInherit.prototype = new Base() 26 | var b = new PrototypeListInherit() 27 | console.log(b.getProperty()) 28 | 29 | /** 30 | * 构造继承 31 | * 原理:基类call、this调用 32 | * 缺点: 只能继承实例,无法继承基类原型的方法 33 | */ 34 | function ConstructInherit() { 35 | Base.call(this) 36 | } 37 | ConstructInherit.prototype.getProperty = function() { 38 | return this.property 39 | } 40 | var c = new ConstructInherit() 41 | console.log(c.getProperty()) 42 | 43 | /** 44 | * 组合继承 45 | * 原理:原型链与构造函数的组合,最后改回原型构造的值 46 | * 优点:既能共享又能单独处理 47 | */ 48 | function ComposeInherit() { 49 | this.property = false 50 | Base.call(this) 51 | } 52 | ComposeInherit.prototype = new Base() 53 | ComposeInherit.prototype.constructor = ComposeInherit 54 | var d = new ComposeInherit() 55 | console.log(d.getProperty()) 56 | 57 | /** 58 | * 原型继承 59 | * 原理:空对象为中介 60 | */ 61 | function PrototypeInherit() {} 62 | -------------------------------------------------------------------------------- /src/javascript/map.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/suoyuesmile/suo-blog/6068b6934e0bcae9b189fcefdc6a6d3752295a29/src/javascript/map.js -------------------------------------------------------------------------------- /src/javascript/new.js: -------------------------------------------------------------------------------- 1 | function A() { 2 | a = 3 3 | } 4 | var a = 5 5 | A() 6 | console.log(a) 7 | -------------------------------------------------------------------------------- /src/javascript/object/copy.js: -------------------------------------------------------------------------------- 1 | const refer1 = { 2 | a: 1 3 | } 4 | 5 | const refer2 = { 6 | refer: refer1 7 | } 8 | 9 | const refer3 = function() { 10 | console.log(1) 11 | } 12 | 13 | const origin = { 14 | a: 1, 15 | b: '1', 16 | c: true, 17 | d: { 18 | e: 1 19 | }, 20 | f: [1, 2], 21 | g: refer2, 22 | h: refer3 23 | } 24 | 25 | function shadowCopy(origin) { 26 | let target = {} 27 | for (const key in origin) { 28 | target[key] = origin[key] 29 | } 30 | return target 31 | } 32 | 33 | function isObject(origin) { 34 | return origin !== null && typeof origin === 'object' 35 | } 36 | 37 | function deepCopy(origin, map = new Map()) { 38 | if (isObject(origin)) { 39 | let target = Array.isArray(origin) ? [] : {} 40 | if (map.get(origin)) return map.get(origin) 41 | map.set(origin, target) 42 | for (const key in origin) { 43 | target[key] = deepCopy(origin[key]) 44 | } 45 | return target 46 | } 47 | return origin 48 | } 49 | 50 | // console.log('shadowCopy1:', shadowCopy(origin)); 51 | 52 | console.log(deepCopy(origin)); 53 | 54 | console.log(Object.assign({}, origin)); 55 | 56 | console.log(JSON.parse(JSON.stringify(origin))); 57 | -------------------------------------------------------------------------------- /src/javascript/object/enum.js: -------------------------------------------------------------------------------- 1 | var origin = { 2 | a: 1, 3 | b: 2 4 | }; 5 | 6 | for (const property in origin) { 7 | console.log(property); 8 | } 9 | 10 | Object.defineProperty(origin, 'a', { 11 | enumerable: false 12 | }) 13 | 14 | 15 | for (const property in origin) { 16 | console.log(origin[property]); 17 | } 18 | 19 | 20 | 21 | // 最好只在Object 遍历数组 22 | var originArray = [1, 2, 4, 6]; 23 | originArray.a = 12 24 | 25 | for (const property in originArray) { 26 | console.log(originArray[property]); 27 | } 28 | 29 | 30 | -------------------------------------------------------------------------------- /src/javascript/object/exist.js: -------------------------------------------------------------------------------- 1 | var origin = { 2 | a: 2 3 | } 4 | 5 | // in 检查对象及其原型链上的属性 无法检查数组 6 | const existIn = 'a' in origin; 7 | 8 | // 不会检查原型链上的属性/ 所有普通对象都可以访问,Object.create(null) 不行 9 | const existHasProperty = origin.hasOwnProperty('a'); 10 | 11 | 12 | for(const property in origin) { 13 | console.log(property); 14 | } 15 | 16 | console.log(existIn, existHasProperty); 17 | -------------------------------------------------------------------------------- /src/javascript/object/get-set.js: -------------------------------------------------------------------------------- 1 | var origin = { 2 | a: 2 3 | } 4 | 5 | 6 | origin = { 7 | get b() { 8 | return 2; 9 | }, 10 | 11 | get c() { 12 | return this._a_; 13 | }, 14 | 15 | set c(val) { 16 | this._a_ = 2 * val; 17 | } 18 | } 19 | 20 | const b = origin.b; 21 | origin.c = 4; 22 | const c = origin.c; 23 | 24 | console.log(b, c); 25 | -------------------------------------------------------------------------------- /src/javascript/object/iterator.js: -------------------------------------------------------------------------------- 1 | // 本身Object 没有迭代器,无法使用 for of 2 | 3 | var origin = { 4 | a: 1, 5 | b: 2 6 | }; 7 | 8 | 9 | Object.defineProperty(origin, Symbol.iterator, { 10 | enumerable: false, 11 | writable: false, 12 | configurable: true, 13 | value: function() { 14 | var o = this; 15 | var idx = 0; 16 | var ks = Object.keys(o); 17 | return { 18 | next: function() { 19 | return { 20 | value: o[ks[idx++]], 21 | done: (idx > ks.length) 22 | } 23 | } 24 | } 25 | } 26 | }) -------------------------------------------------------------------------------- /src/javascript/object/property-desciptor.js: -------------------------------------------------------------------------------- 1 | var origin = { 2 | a: 1 3 | } 4 | 5 | const descriptor = Object.getOwnPropertyDescriptor(origin, 'a'); 6 | 7 | Object.defineProperty(origin, 'a', { 8 | value: 2, 9 | writable: false, 10 | // 无法改变 11 | configurable: false, 12 | // 无法再通过defineProperty 修改,也无法删除 13 | emumerable: false 14 | // 无法通过 for in 来枚举 15 | }) 16 | 17 | 18 | console.log(origin); 19 | 20 | origin.a = 3; 21 | 22 | console.log(origin); -------------------------------------------------------------------------------- /src/javascript/object/traverse.js: -------------------------------------------------------------------------------- 1 | // 两种 2 | var origin = { 3 | a: 1, 4 | b: true, 5 | c: 'c' 6 | }; 7 | 8 | var originArr = [1, 3, 4, 5]; 9 | 10 | // 遍历属性或者下标, 遍历对象 11 | 12 | for (const property in origin) { 13 | console.log(property); 14 | } 15 | 16 | for (const property in originArr) { 17 | console.log(property); 18 | } 19 | 20 | 21 | // 遍历值, 遍历数组 22 | 23 | for (const item of origin) { 24 | console.log(item); 25 | } 26 | 27 | for (const item of originArr) { 28 | console.log(item); 29 | } 30 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /src/javascript/promise.js: -------------------------------------------------------------------------------- 1 | const PENDING = 'pending' 2 | const FULFILLED = 'fulfilled' 3 | const REJECTED = 'rejected' 4 | function Promise() { 5 | let that = this 6 | that.status = PENDING 7 | this.value = undefined 8 | this.rejectedReason = undefined 9 | that.fulfilledCallbackInfo = undefined 10 | that.rejectedCallbackInfo = undefined 11 | that.onFulfillCallbacks = [] 12 | that.onRejectedCallbacks = [] 13 | 14 | function resolve(value) { 15 | if (val instanceof Promise) { 16 | return val.then(resolve, reject) 17 | } 18 | 19 | setTimeout(() => { 20 | if (that.status === PENDING) { 21 | that.status = FULFILLED 22 | that.value = value 23 | this.onFulfillCallbacks.forEach(cb => cb(that.value)) 24 | } 25 | }) 26 | } 27 | 28 | function rejected(val) { 29 | setTimeout(() => { 30 | if (that.status === PENDING) { 31 | that.status = REJECTED 32 | that.rejectedReason = value 33 | that.onRejectedCallbacks.forEach(cb => cb(that.rejectedReason)) 34 | } 35 | }) 36 | } 37 | } 38 | 39 | function resolvePromise() {} 40 | Promise.prototype.then = function(onResolve, onRejected) {} 41 | Promise.all = function() {} 42 | Promise.race = function() {} 43 | Promise.resolve = function() {} 44 | Promise.reject = function() {} 45 | Promise.catch = function() {} 46 | -------------------------------------------------------------------------------- /src/javascript/proto.js: -------------------------------------------------------------------------------- 1 | var a = { 2 | name: '123' 3 | } 4 | 5 | function B() {} 6 | var b = new B() 7 | 8 | console.log(a.__proto__) // {} 9 | console.log(b.__proto__) // B {} 10 | console.log(B.prototype) // B {} 11 | console.log(B.__proto__) // [Function] 12 | console.log(b.__proto__ === B.prototype) // true 13 | console.log(B.prototype.constructor === B) // true 14 | console.log(B.prototype.constructor === b.__proto__.constructor) 15 | console.log(B.prototype.__proto__) // {} 16 | 17 | var c = Object.create(a) 18 | console.log(c.__proto__ === a) // true 19 | 20 | // B 为构造函数 21 | // b 为实例 22 | // B 里面有个原型prototype对象,原型对象里面有个contructor指向自身 23 | // B 里面有个 __proto__ 指向函数,函数里面有个__proto__ 指向对象 24 | // b 里面有个 __proto__ 指向B的原型 b.__proto__ === B.prototype 25 | // 因此 b里面的__proto__ 也有个contructor 指向 B, b.__proto__.constructor === B.prototype.constructor === B 26 | -------------------------------------------------------------------------------- /src/javascript/proxy/base.js: -------------------------------------------------------------------------------- 1 | // 用于定义基本操作的自定义行为 2 | 3 | const p = new Proxy({}, {}); 4 | 5 | console.log(p); 6 | 7 | var pipe = function (value) { 8 | var funcStack = []; 9 | var oproxy = new Proxy({}, { 10 | get: function (pipeObject, fnName) { 11 | if (fnName === 'get') { 12 | return funcStack.reduce(function (val, fn) { 13 | return fn(val); 14 | }, value); 15 | } 16 | funcStack.push(window[fnName]); 17 | return oproxy; 18 | } 19 | }); 20 | 21 | return oproxy; 22 | } 23 | 24 | var double = n => n * 2; 25 | var pow = n => n * n; 26 | var reverseInt = n => n.toString().split("").reverse().join("") | 0; 27 | 28 | pipe(3) -------------------------------------------------------------------------------- /src/javascript/regExp.js: -------------------------------------------------------------------------------- 1 | // assert 断言 2 | 3 | // match 4 | // exec 5 | // test 6 | // search 7 | // replace 8 | // split 9 | // filter 10 | 11 | const text = '09:00-19:00'; 12 | 13 | const pattern = /^[0-2][0-9]:[0-5][0-9]-[0-2][0-9]:[0-5][0-9]$/; 14 | 15 | 16 | // console.log(text.match(pattern)); 17 | // console.log(text.search(pattern)); 18 | // console.log(text.split(pattern)); 19 | // // console.log(text.filter(pattern)); 20 | // console.log(pattern.test(text)); 21 | // console.log(pattern.exec(text)); 22 | 23 | let demo = 'https://developer.mozilla.org///en-US//docs/Web/JavaScript/Guide/Regular_Expressions'; 24 | 25 | demo = demo.replace(/([\/]{2,})/g, '/'); 26 | 27 | console.log(demo); 28 | 29 | -------------------------------------------------------------------------------- /src/javascript/scope.js: -------------------------------------------------------------------------------- 1 | function a() { 2 | b = 2 3 | // this.b = 2 4 | } 5 | 6 | var b = 1 7 | 8 | a() 9 | 10 | console.log(b) 11 | -------------------------------------------------------------------------------- /src/javascript/set.js: -------------------------------------------------------------------------------- 1 | const s1 = new Set([1, 3, 2, 3]); 2 | console.log(s1); 3 | // console.log([...new Set([1, 3, 2, 3])]); // 取唯一 4 | 5 | // 判断是否存在某个值 6 | // console.log(s1.has(2)); 7 | 8 | 9 | // 判断交集 10 | function intersection(s1, s2) { 11 | // 短的取比长的 12 | if (s1.size > s2.size) { 13 | return intersection(s2, s1); 14 | } 15 | const intersectionSet = new Set(); 16 | for (const num of s1) { 17 | if (s2.has(num)) { 18 | intersectionSet.add(num) 19 | } 20 | } 21 | return [...intersectionSet]; 22 | } 23 | 24 | console.log(intersection(new Set([1, 3, 5, 7, 9]), new Set([2, 4, 6, 7]))); 25 | -------------------------------------------------------------------------------- /src/javascript/set/set.js: -------------------------------------------------------------------------------- 1 | const s1 = new Set([1, 3, 2, 3]); 2 | console.log(s1); 3 | // console.log([...new Set([1, 3, 2, 3])]); // 取唯一 4 | 5 | // 判断是否存在某个值 6 | // console.log(s1.has(2)); 7 | 8 | 9 | // 判断交集 10 | function intersection(s1, s2) { 11 | // 短的取比长的 12 | if (s1.size > s2.size) { 13 | return intersection(s2, s1); 14 | } 15 | const intersectionSet = new Set(); 16 | for (const num of s1) { 17 | if (s2.has(num)) { 18 | intersectionSet.add(num) 19 | } 20 | } 21 | return [...intersectionSet]; 22 | } 23 | 24 | console.log(intersection(new Set([1, 3, 5, 7, 9]), new Set([2, 4, 6, 7]))); 25 | -------------------------------------------------------------------------------- /src/javascript/sleep.js: -------------------------------------------------------------------------------- 1 | function sleep(milliseconds) { 2 | const startTime = new Date().getTime(); 3 | while(new Date().getTime() < startTime + milliseconds); 4 | } 5 | sleep(10000); -------------------------------------------------------------------------------- /src/javascript/string.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/suoyuesmile/suo-blog/6068b6934e0bcae9b189fcefdc6a6d3752295a29/src/javascript/string.js -------------------------------------------------------------------------------- /src/javascript/this.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/suoyuesmile/suo-blog/6068b6934e0bcae9b189fcefdc6a6d3752295a29/src/javascript/this.js -------------------------------------------------------------------------------- /src/javascript/throttle.js: -------------------------------------------------------------------------------- 1 | /** 2 | * 任务在某一特定的时间内,不会被调用两次 3 | */ 4 | function throttle(fn, wait) { 5 | let runable = false 6 | setTimeout(() => { 7 | fn.call(this, arguments) 8 | runable = true 9 | }, wait) 10 | } 11 | 12 | /** 13 | * 使用时间轴存值 14 | */ 15 | 16 | function throttle(fn, wait) { 17 | let last = 0 18 | return function() { 19 | setTimeout(() => { 20 | let start = +new Date() 21 | if (start - last > wait) { 22 | fn.apply(this, arguments) 23 | last = start 24 | } 25 | }, wait) 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/javascript/type.js: -------------------------------------------------------------------------------- 1 | const object = { 2 | a: undefined, 3 | b: 1, 4 | c: '1', 5 | d: true, 6 | e: {}, 7 | f: [], 8 | g: function() {}, 9 | h: NaN, 10 | i: null, 11 | j: new Date(), 12 | k: new String(), 13 | l: new RegExp() 14 | } 15 | 16 | // 通用方法 17 | for (const key in object) { 18 | console.log(Object.prototype.toString.call(object[key])) 19 | } 20 | 21 | // [object Undefined] 22 | // [object Number] 23 | // [object String] 24 | // [object Boolean] 25 | // [object Object] 26 | // [object Array] 27 | // [object Function] 28 | // [object Number] 29 | // [object Null] 30 | // [object Date] 31 | 32 | for (const key in object) { 33 | console.log(typeof object[key]) 34 | } 35 | 36 | // undefined 37 | // number 38 | // string 39 | // boolean 40 | // object 41 | // object 42 | // function 43 | // number 44 | // object 45 | // object 46 | // object 47 | // object 48 | -------------------------------------------------------------------------------- /src/javascript/uniqu.js: -------------------------------------------------------------------------------- 1 | const array = [1, 3, 2, 6, 2, 3, 4, 7, 8, 9, 10] 2 | function set_uniqu(array) { 3 | return [...new Set(array)] 4 | } 5 | 6 | function filter_uniqu(array) { 7 | return array.filter((item, index) => array.indexOf(item) === index) 8 | } 9 | 10 | function filter_map_uniqu(array) {} 11 | function reduce_uniqu(array) { 12 | return array.reduce( 13 | (prev, cur, index, array) => 14 | prev.includes(cur) ? prev : prev.concat(cur), 15 | [] 16 | ) 17 | } 18 | console.log('newSet', set_uniqu(array)) 19 | console.log('filter', filter_uniqu(array)) 20 | console.log('reduce', reduce_uniqu(array)) 21 | -------------------------------------------------------------------------------- /src/json/data.json: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /src/koa/db/index.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/suoyuesmile/suo-blog/6068b6934e0bcae9b189fcefdc6a6d3752295a29/src/koa/db/index.js -------------------------------------------------------------------------------- /src/koa/index.js: -------------------------------------------------------------------------------- 1 | const koa = require('koa') 2 | const app = new koa(); 3 | 4 | app.use(async ctx => { 5 | ctx.body = 'hello world'; 6 | }) 7 | 8 | app.listen(3000); -------------------------------------------------------------------------------- /src/leetcode/1.两数之和.js: -------------------------------------------------------------------------------- 1 | /* 2 | * @lc app=leetcode.cn id=1 lang=javascript 3 | * 4 | * [1] 两数之和 5 | */ 6 | 7 | // @lc code=start 8 | /** 9 | * @param {number[]} nums 10 | * @param {number} target 11 | * @return {number[]} 12 | */ 13 | var twoSum = function(nums, target) { 14 | const len = nums.length 15 | const map = new Map() 16 | for (let i = 0; i < len; i++) { 17 | map.set(nums[i], i) 18 | } 19 | 20 | for (let i = 0; i < len; i++) { 21 | const j = map.get(target - nums[i]) 22 | if (map.has(target - nums[i])) { 23 | if (2 * nums[i] === target && i === j) continue 24 | return [i, j] 25 | } 26 | } 27 | } 28 | // @lc code=end 29 | -------------------------------------------------------------------------------- /src/leetcode/2.两数相加.js: -------------------------------------------------------------------------------- 1 | /* 2 | * @lc app=leetcode.cn id=2 lang=javascript 3 | * 4 | * [2] 两数相加 5 | * 6 | * https://leetcode-cn.com/problems/add-two-numbers/description/ 7 | * 8 | * algorithms 9 | * Medium (36.28%) 10 | * Likes: 3672 11 | * Dislikes: 0 12 | * Total Accepted: 292.3K 13 | * Total Submissions: 805.4K 14 | * Testcase Example: '[2,4,3]\n[5,6,4]' 15 | * 16 | * 给出两个 非空 的链表用来表示两个非负的整数。其中,它们各自的位数是按照 逆序 的方式存储的,并且它们的每个节点只能存储 一位 数字。 17 | * 18 | * 如果,我们将这两个数相加起来,则会返回一个新的链表来表示它们的和。 19 | * 20 | * 您可以假设除了数字 0 之外,这两个数都不会以 0 开头。 21 | * 22 | * 示例: 23 | * 24 | * 输入:(2 -> 4 -> 3) + (5 -> 6 -> 4) 25 | * 输出:7 -> 0 -> 8 26 | * 原因:342 + 465 = 807 27 | * 28 | * 29 | */ 30 | 31 | // @lc code=start 32 | /** 33 | * Definition for singly-linked list. 34 | * function ListNode(val) { 35 | * this.val = val; 36 | * this.next = null; 37 | * } 38 | */ 39 | /** 40 | * @param {ListNode} l1 41 | * @param {ListNode} l2 42 | * @return {ListNode} 43 | */ 44 | var addTwoNumbers = function(l1, l2) { 45 | console.log(l1, l2) 46 | } 47 | 48 | var l1 = new ListNode() 49 | 50 | // @lc code=end 51 | -------------------------------------------------------------------------------- /src/leetcode/21.合并两个有序链表.js: -------------------------------------------------------------------------------- 1 | /* 2 | * @lc app=leetcode.cn id=21 lang=javascript 3 | * 4 | * [21] 合并两个有序链表 5 | * 6 | * https://leetcode-cn.com/problems/merge-two-sorted-lists/description/ 7 | * 8 | * algorithms 9 | * Easy (58.91%) 10 | * Likes: 791 11 | * Dislikes: 0 12 | * Total Accepted: 160.9K 13 | * Total Submissions: 273K 14 | * Testcase Example: '[1,2,4]\n[1,3,4]' 15 | * 16 | * 将两个有序链表合并为一个新的有序链表并返回。新链表是通过拼接给定的两个链表的所有节点组成的。 17 | * 18 | * 示例: 19 | * 20 | * 输入:1->2->4, 1->3->4 21 | * 输出:1->1->2->3->4->4 22 | * 23 | * 24 | */ 25 | 26 | // @lc code=start 27 | /** 28 | * Definition for singly-linked list. 29 | * function ListNode(val) { 30 | * this.val = val; 31 | * this.next = null; 32 | * } 33 | */ 34 | /** 35 | * @param {ListNode} l1 36 | * @param {ListNode} l2 37 | * @return {ListNode} 38 | */ 39 | var mergeTwoLists = function(l1, l2) { 40 | return l1.next 41 | } 42 | // @lc code=end 43 | -------------------------------------------------------------------------------- /src/leetcode/28.实现-str-str.js: -------------------------------------------------------------------------------- 1 | /* 2 | * @lc app=leetcode.cn id=28 lang=javascript 3 | * 4 | * [28] 实现 strStr() 5 | * 6 | * https://leetcode-cn.com/problems/implement-strstr/description/ 7 | * 8 | * algorithms 9 | * Easy (39.26%) 10 | * Likes: 335 11 | * Dislikes: 0 12 | * Total Accepted: 114.1K 13 | * Total Submissions: 290.4K 14 | * Testcase Example: '"hello"\n"ll"' 15 | * 16 | * 实现 strStr() 函数。 17 | * 18 | * 给定一个 haystack 字符串和一个 needle 字符串,在 haystack 字符串中找出 needle 字符串出现的第一个位置 19 | * (从0开始)。如果不存在,则返回  -1。 20 | * 21 | * 示例 1: 22 | * 23 | * 输入: haystack = "hello", needle = "ll" 24 | * 输出: 2 25 | * 26 | * 27 | * 示例 2: 28 | * 29 | * 输入: haystack = "aaaaa", needle = "bba" 30 | * 输出: -1 31 | * 32 | * 33 | * 说明: 34 | * 35 | * 当 needle 是空字符串时,我们应当返回什么值呢?这是一个在面试中很好的问题。 36 | * 37 | * 对于本题而言,当 needle 是空字符串时我们应当返回 0 。这与C语言的 strstr() 以及 Java的 indexOf() 定义相符。 38 | * 39 | */ 40 | 41 | // @lc code=start 42 | /** 43 | * @param {string} haystack 44 | * @param {string} needle 45 | * @return {number} 46 | */ 47 | 48 | var strStr = function(haystack, needle) { 49 | return haystack.indexOf(needle) 50 | } 51 | // @lc code=end 52 | -------------------------------------------------------------------------------- /src/leetcode/3.无重复字符的最长子串.js: -------------------------------------------------------------------------------- 1 | /* 2 | * @lc app=leetcode.cn id=3 lang=javascript 3 | * 4 | * [3] 无重复字符的最长子串 5 | * 6 | * https://leetcode-cn.com/problems/longest-substring-without-repeating-characters/description/ 7 | * 8 | * algorithms 9 | * Medium (32.36%) 10 | * Likes: 2972 11 | * Dislikes: 0 12 | * Total Accepted: 314K 13 | * Total Submissions: 968.3K 14 | * Testcase Example: '"abcabcbb"' 15 | * 16 | * 给定一个字符串,请你找出其中不含有重复字符的 最长子串 的长度。 17 | * 18 | * 示例 1: 19 | * 20 | * 输入: "abcabcbb" 21 | * 输出: 3 22 | * 解释: 因为无重复字符的最长子串是 "abc",所以其长度为 3。 23 | * 24 | * 25 | * 示例 2: 26 | * 27 | * 输入: "bbbbb" 28 | * 输出: 1 29 | * 解释: 因为无重复字符的最长子串是 "b",所以其长度为 1。 30 | * 31 | * 32 | * 示例 3: 33 | * 34 | * 输入: "pwwkew" 35 | * 输出: 3 36 | * 解释: 因为无重复字符的最长子串是 "wke",所以其长度为 3。 37 | * 请注意,你的答案必须是 子串 的长度,"pwke" 是一个子序列,不是子串。 38 | * 39 | * 40 | */ 41 | 42 | // @lc code=start 43 | /** 44 | * @param {string} s 45 | * @return {number} 46 | */ 47 | var lengthOfLongestSubstring = function(s) { 48 | if (s.length <= 1) { 49 | return s.length 50 | } 51 | var max = 1 52 | var tempIndex = 0 53 | for (let i = 0; i < s.length; i++) { 54 | for (let j = i; j < s.length; j++) { 55 | if (s[j] === s[tempIndex]) { 56 | max = Math.max(max, j - tempIndex) 57 | tempIndex = j 58 | } 59 | } 60 | } 61 | return max > 1 ? max : s.length 62 | } 63 | // @lc code=end 64 | -------------------------------------------------------------------------------- /src/leetcode/35.搜索插入位置.js: -------------------------------------------------------------------------------- 1 | /* 2 | * @lc app=leetcode.cn id=35 lang=javascript 3 | * 4 | * [35] 搜索插入位置 5 | * 6 | * https://leetcode-cn.com/problems/search-insert-position/description/ 7 | * 8 | * algorithms 9 | * Easy (44.77%) 10 | * Likes: 398 11 | * Dislikes: 0 12 | * Total Accepted: 104K 13 | * Total Submissions: 232.2K 14 | * Testcase Example: '[1,3,5,6]\n5' 15 | * 16 | * 给定一个排序数组和一个目标值,在数组中找到目标值,并返回其索引。如果目标值不存在于数组中,返回它将会被按顺序插入的位置。 17 | * 18 | * 你可以假设数组中无重复元素。 19 | * 20 | * 示例 1: 21 | * 22 | * 输入: [1,3,5,6], 5 23 | * 输出: 2 24 | * 25 | * 26 | * 示例 2: 27 | * 28 | * 输入: [1,3,5,6], 2 29 | * 输出: 1 30 | * 31 | * 32 | * 示例 3: 33 | * 34 | * 输入: [1,3,5,6], 7 35 | * 输出: 4 36 | * 37 | * 38 | * 示例 4: 39 | * 40 | * 输入: [1,3,5,6], 0 41 | * 输出: 0 42 | * 43 | * 44 | */ 45 | 46 | // @lc code=start 47 | /** 48 | * @param {number[]} nums 49 | * @param {number} target 50 | * @return {number} 51 | */ 52 | var searchInsert = function(nums, target) { 53 | var hi = nums.length - 1, 54 | lo = 0 55 | 56 | // 2.迭代,换界 57 | while (hi - lo >= 0) { 58 | var mi = (hi + lo) >>> 1 59 | if (target < nums[mi]) { 60 | hi = mi - 1 61 | } else if (nums[mi] < target) { 62 | lo = mi + 1 63 | } else { 64 | return mi 65 | } 66 | } 67 | return lo 68 | } 69 | searchInsert([1, 3, 5, 6], 2) 70 | // @lc code=end 71 | -------------------------------------------------------------------------------- /src/leetcode/53.最大子序和.js: -------------------------------------------------------------------------------- 1 | /* 2 | * @lc app=leetcode.cn id=53 lang=javascript 3 | * 4 | * [53] 最大子序和 5 | * 6 | * https://leetcode-cn.com/problems/maximum-subarray/description/ 7 | * 8 | * algorithms 9 | * Easy (48.54%) 10 | * Likes: 1478 11 | * Dislikes: 0 12 | * Total Accepted: 141.2K 13 | * Total Submissions: 290.6K 14 | * Testcase Example: '[-2,1,-3,4,-1,2,1,-5,4]' 15 | * 16 | * 给定一个整数数组 nums ,找到一个具有最大和的连续子数组(子数组最少包含一个元素),返回其最大和。 17 | * 18 | * 示例: 19 | * 20 | * 输入: [-2,1,-3,4,-1,2,1,-5,4], 21 | * 输出: 6 22 | * 解释: 连续子数组 [4,-1,2,1] 的和最大,为 6。 23 | * 24 | * 25 | * 进阶: 26 | * 27 | * 如果你已经实现复杂度为 O(n) 的解法,尝试使用更为精妙的分治法求解。 28 | * 29 | */ 30 | 31 | // @lc code=start 32 | /** 33 | * @param {number[]} nums 34 | * @return {number} 35 | */ 36 | var maxSubArray = function(nums) {} 37 | // @lc code=end 38 | -------------------------------------------------------------------------------- /src/leetcode/58.最后一个单词的长度.js: -------------------------------------------------------------------------------- 1 | /* 2 | * @lc app=leetcode.cn id=58 lang=javascript 3 | * 4 | * [58] 最后一个单词的长度 5 | * 6 | * https://leetcode-cn.com/problems/length-of-last-word/description/ 7 | * 8 | * algorithms 9 | * Easy (31.95%) 10 | * Likes: 164 11 | * Dislikes: 0 12 | * Total Accepted: 60.5K 13 | * Total Submissions: 189K 14 | * Testcase Example: '"Hello World"' 15 | * 16 | * 给定一个仅包含大小写字母和空格 ' ' 的字符串,返回其最后一个单词的长度。 17 | * 18 | * 如果不存在最后一个单词,请返回 0 。 19 | * 20 | * 说明:一个单词是指由字母组成,但不包含任何空格的字符串。 21 | * 22 | * 示例: 23 | * 24 | * 输入: "Hello World" 25 | * 输出: 5 26 | * 27 | * 28 | */ 29 | 30 | // @lc code=start 31 | /** 32 | * @param {string} s 33 | * @return {number} 34 | */ 35 | // var trimRight = function(s) { 36 | // var i = s.length 37 | // while (--i && s[i] === ' ') { 38 | // s = s.slice(0, i) 39 | // } 40 | // return s 41 | // } 42 | // var lengthOfLastWord = function(s) { 43 | // var i = s.length 44 | // if (!i) return 0 45 | // s = trimRight(s) 46 | // while (--i >= 0) { 47 | // if (s[i] === ' ') { 48 | // return s.length - 1 - i 49 | // } 50 | // } 51 | // return s.length 52 | // } 53 | var lengthOfLastWord = function(s) { 54 | s = s.trim() 55 | return s.length - 1 - s.lastIndexOf(' ') 56 | } 57 | 58 | // @lc code=end 59 | -------------------------------------------------------------------------------- /src/leetcode/66.加一.js: -------------------------------------------------------------------------------- 1 | /* 2 | * @lc app=leetcode.cn id=66 lang=javascript 3 | * 4 | * [66] 加一 5 | * 6 | * https://leetcode-cn.com/problems/plus-one/description/ 7 | * 8 | * algorithms 9 | * Easy (42.30%) 10 | * Likes: 402 11 | * Dislikes: 0 12 | * Total Accepted: 107.1K 13 | * Total Submissions: 252.6K 14 | * Testcase Example: '[1,2,3]' 15 | * 16 | * 给定一个由整数组成的非空数组所表示的非负整数,在该数的基础上加一。 17 | * 18 | * 最高位数字存放在数组的首位, 数组中每个元素只存储单个数字。 19 | * 20 | * 你可以假设除了整数 0 之外,这个整数不会以零开头。 21 | * 22 | * 示例 1: 23 | * 24 | * 输入: [1,2,3] 25 | * 输出: [1,2,4] 26 | * 解释: 输入数组表示数字 123。 27 | * 28 | * 29 | * 示例 2: 30 | * 31 | * 输入: [4,3,2,1] 32 | * 输出: [4,3,2,2] 33 | * 解释: 输入数组表示数字 4321。 34 | * 35 | * 36 | */ 37 | 38 | // @lc code=start 39 | /** 40 | * @param {number[]} digits 41 | * @return {number[]} 42 | */ 43 | var plusOne = function(digits) { 44 | digits[digits.length - 1] = digits[digits.length - 1] + 1 45 | for (let i = digits.length - 1; i >= 0; i--) { 46 | if (digits[i] !== 10) return digits 47 | digits[i] = 0 48 | if (i > 0) { 49 | digits[i - 1] = digits[i - 1] + 1 50 | } else { 51 | digits.splice(0, 0, 1) 52 | } 53 | } 54 | return digits 55 | } 56 | // @lc code=end 57 | -------------------------------------------------------------------------------- /src/leetcode/67.二进制求和.js: -------------------------------------------------------------------------------- 1 | /* 2 | * @lc app=leetcode.cn id=67 lang=javascript 3 | * 4 | * [67] 二进制求和 5 | * 6 | * https://leetcode-cn.com/problems/add-binary/description/ 7 | * 8 | * algorithms 9 | * Easy (51.70%) 10 | * Likes: 283 11 | * Dislikes: 0 12 | * Total Accepted: 56.3K 13 | * Total Submissions: 108.5K 14 | * Testcase Example: '"11"\n"1"' 15 | * 16 | * 给定两个二进制字符串,返回他们的和(用二进制表示)。 17 | * 18 | * 输入为非空字符串且只包含数字 1 和 0。 19 | * 20 | * 示例 1: 21 | * 22 | * 输入: a = "11", b = "1" 23 | * 输出: "100" 24 | * 25 | * 示例 2: 26 | * 27 | * 输入: a = "1010", b = "1011" 28 | * 输出: "10101" 29 | * 30 | */ 31 | 32 | // @lc code=start 33 | /** 34 | * @param {string} a 35 | * @param {string} b 36 | * @return {string} 37 | */ 38 | var addBinary = function(a, b) { 39 | // return (parseInt(a, 2) + parseInt(b, 2)).toString(2) 40 | } 41 | addBinary( 42 | '10100000100100110110010000010101111011011001101110111111111101000000101111001110001111100001101', 43 | '110101001011101110001111100110001010100001101011101010000011011011001011101111001100000011011110011' 44 | ) // @lc code=end 45 | -------------------------------------------------------------------------------- /src/leetcode/69.x-的平方根.js: -------------------------------------------------------------------------------- 1 | /* 2 | * @lc app=leetcode.cn id=69 lang=javascript 3 | * 4 | * [69] x 的平方根 5 | * 6 | * https://leetcode-cn.com/problems/sqrtx/description/ 7 | * 8 | * algorithms 9 | * Easy (37.32%) 10 | * Likes: 277 11 | * Dislikes: 0 12 | * Total Accepted: 83.8K 13 | * Total Submissions: 224.3K 14 | * Testcase Example: '4' 15 | * 16 | * 实现 int sqrt(int x) 函数。 17 | * 18 | * 计算并返回 x 的平方根,其中 x 是非负整数。 19 | * 20 | * 由于返回类型是整数,结果只保留整数的部分,小数部分将被舍去。 21 | * 22 | * 示例 1: 23 | * 24 | * 输入: 4 25 | * 输出: 2 26 | * 27 | * 28 | * 示例 2: 29 | * 30 | * 输入: 8 31 | * 输出: 2 32 | * 说明: 8 的平方根是 2.82842..., 33 | * 由于返回类型是整数,小数部分将被舍去。 34 | * 35 | * 36 | */ 37 | 38 | // @lc code=start 39 | /** 40 | * @param {number} x 41 | * @return {number} 42 | */ 43 | var mySqrt = function(x) { 44 | if (x === 0) return 0 45 | if (x <= 3) return 1 46 | if (x <= 5) return 2 47 | for (let i = 2; i <= x / 2; i++) { 48 | if (i * i > x) { 49 | return i - 1 50 | } 51 | } 52 | } 53 | // @lc code=end 54 | -------------------------------------------------------------------------------- /src/leetcode/7.整数反转.js: -------------------------------------------------------------------------------- 1 | /* 2 | * @lc app=leetcode.cn id=7 lang=javascript 3 | * 4 | * [7] 整数反转 5 | */ 6 | 7 | // @lc code=start 8 | /** 9 | * @param {number} x 10 | * @return {number} 11 | */ 12 | var reverse = function(x) { 13 | var max = Math.pow(2, 31) - 1 14 | var min = -Math.pow(2, 31) 15 | var temp = x > 0 ? x : -1 * x 16 | var stack = [] 17 | var result = 0 18 | while (temp > 0) { 19 | stack.push(Math.floor(temp % 10)) 20 | temp = Math.floor(temp / 10) 21 | } 22 | temp = 1 23 | var i = stack.length 24 | while (i-- > 0) { 25 | result = result + stack[i] * temp 26 | temp = temp * 10 27 | } 28 | if (x > 0) { 29 | return result <= max ? result : 0 30 | } else { 31 | return -result >= min ? -result : 0 32 | } 33 | } 34 | 35 | // @lc code=end 36 | -------------------------------------------------------------------------------- /src/leetcode/9.回文数.js: -------------------------------------------------------------------------------- 1 | /* 2 | * @lc app=leetcode.cn id=9 lang=javascript 3 | * 4 | * [9] 回文数 5 | */ 6 | 7 | // @lc code=start 8 | /** 9 | * @param {number} x 10 | * @return {boolean} 11 | */ 12 | var isPalindrome = function(x) { 13 | var str = String(x) 14 | return ( 15 | str 16 | .split('') 17 | .reverse() 18 | .join('') === str 19 | ) 20 | } 21 | // @lc code=end 22 | -------------------------------------------------------------------------------- /src/linux/process_manage.sh: -------------------------------------------------------------------------------- 1 | # sh 2 | 3 | # top 4 | 5 | 6 | # ps 7 | # 查找进程 8 | ps -fA | grep [name] -------------------------------------------------------------------------------- /src/node/app/index.js: -------------------------------------------------------------------------------- 1 | const server = require('./server'); 2 | const router = require('./router'); 3 | const requestHandles = require('./requestHandles'); 4 | 5 | const handles = {}; 6 | handles['/'] = requestHandles.start; 7 | handles['/upload'] = requestHandles.upload; 8 | handles['/show'] = requestHandles.show; 9 | 10 | server.createServer(router.route, handles); -------------------------------------------------------------------------------- /src/node/app/router.js: -------------------------------------------------------------------------------- 1 | function route(pathname, handles, response, request) { 2 | console.log(pathname); 3 | if (typeof handles[pathname] === 'function') { 4 | return handles[pathname](response, request); 5 | } else { 6 | response.writeHead(200, {'Content-Type': 'text/plain'}); 7 | response.write('404 not found!'); 8 | response.end() 9 | } 10 | } 11 | 12 | exports.route = route; -------------------------------------------------------------------------------- /src/node/app/server.js: -------------------------------------------------------------------------------- 1 | const http = require('http'); 2 | const url = require('url'); 3 | 4 | function createServer(route, handles) { 5 | http.createServer(function(request, response) { 6 | const pathname = url.parse(request.url).pathname; 7 | route(pathname, handles, response, request); 8 | }).listen(8888); 9 | console.log('server ok!') 10 | } 11 | 12 | exports.createServer = createServer; 13 | 14 | -------------------------------------------------------------------------------- /src/node/file/file-download.js: -------------------------------------------------------------------------------- 1 | const fs = require('fs'); 2 | const path = require('path'); 3 | const request = require('request'); 4 | 5 | const url = ''; 6 | // fs.readFile(url, (err, data) => { 7 | // if (err) { 8 | // console.log(err) 9 | // } 10 | // console.log(data.toString()); 11 | // }) 12 | 13 | var dirPath = path.join(__dirname, "file"); 14 | if (!fs.existsSync(dirPath)) { 15 | fs.mkdirSync(dirPath); 16 | console.log("文件夹创建成功"); 17 | } else { 18 | console.log("文件夹已存在"); 19 | } 20 | 21 | let stream = fs.createWriteStream(dirPath + 'aa.jpg'); 22 | request(url).pipe(stream).on("close", function (err) { 23 | console.log("文件下载完毕"); 24 | }); 25 | -------------------------------------------------------------------------------- /src/node/file/file-read.js: -------------------------------------------------------------------------------- 1 | const fs = require('fs'); 2 | const path = require('path'); 3 | const dirPath = path.join(__dirname, "file"); 4 | const url = dirPath + 'fileaa.js'; 5 | fs.readFileSync(dirPath + 'aa.js', (err, data) => { 6 | console.log(data.toString()) 7 | }) -------------------------------------------------------------------------------- /src/node/file/fileaa.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/suoyuesmile/suo-blog/6068b6934e0bcae9b189fcefdc6a6d3752295a29/src/node/file/fileaa.jpg -------------------------------------------------------------------------------- /src/node/node-fetch/index.js: -------------------------------------------------------------------------------- 1 | const fetch = require('node-fetch'); 2 | const FormData = require('form-data'); 3 | 4 | const form = new FormData(); 5 | form.append('a', 1); 6 | 7 | (async () => { 8 | const response = await fetch('https://httpbin.org/post', {method: 'POST', body: form}); 9 | const json = await response.json(); 10 | 11 | console.log(json) 12 | })(); 13 | 14 | // OR, using custom headers 15 | // NOTE: getHeaders() is non-standard API 16 | 17 | const options = { 18 | method: 'POST', 19 | body: form, 20 | headers: form.getHeaders() 21 | }; 22 | 23 | (async () => { 24 | const response = await fetch('https://httpbin.org/post', options); 25 | const json = await response.json(); 26 | 27 | console.log(json) 28 | })(); -------------------------------------------------------------------------------- /src/question/interserction.js: -------------------------------------------------------------------------------- 1 | function set_intersection(set1, set2) { 2 | if (set1.size > set2.size) { 3 | return set_intersection(set2, set1); 4 | } 5 | 6 | const intersection = new Set(); 7 | for (const num of set1) { 8 | if (set2.has(num)) { 9 | intersection.add(num); 10 | } 11 | } 12 | return [...intersection]; 13 | } 14 | 15 | function intersection(nums1, nums2) { 16 | const set1 = new Set(nums1); 17 | const set2 = new Set(nums2); 18 | 19 | return set_intersection(set1, set2); 20 | } 21 | 22 | console.log(intersection([1, 2, 4], [2, 3])); -------------------------------------------------------------------------------- /src/react/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/suoyuesmile/suo-blog/6068b6934e0bcae9b189fcefdc6a6d3752295a29/src/react/.DS_Store -------------------------------------------------------------------------------- /src/react/app/.gitignore: -------------------------------------------------------------------------------- 1 | # See https://help.github.com/articles/ignoring-files/ for more about ignoring files. 2 | 3 | # dependencies 4 | /node_modules 5 | /.pnp 6 | .pnp.js 7 | 8 | # testing 9 | /coverage 10 | 11 | # production 12 | /build 13 | 14 | # misc 15 | .DS_Store 16 | .env.local 17 | .env.development.local 18 | .env.test.local 19 | .env.production.local 20 | 21 | npm-debug.log* 22 | yarn-debug.log* 23 | yarn-error.log* 24 | -------------------------------------------------------------------------------- /src/react/app/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "app", 3 | "version": "0.1.0", 4 | "private": true, 5 | "dependencies": { 6 | "@testing-library/jest-dom": "^4.2.4", 7 | "@testing-library/react": "^9.3.2", 8 | "@testing-library/user-event": "^7.1.2", 9 | "antd": "^4.2.0", 10 | "antd-mobile": "^2.3.1", 11 | "ky-universal": "^0.7.0", 12 | "node-sass": "^4.14.1", 13 | "react": "^16.13.1", 14 | "react-dom": "^16.13.1", 15 | "react-router": "^5.1.2", 16 | "react-router-dom": "^5.1.2", 17 | "react-scripts": "3.4.1" 18 | }, 19 | "scripts": { 20 | "start": "react-scripts start", 21 | "build": "react-scripts build", 22 | "test": "react-scripts test", 23 | "eject": "react-scripts eject" 24 | }, 25 | "eslintConfig": { 26 | "extends": "react-app" 27 | }, 28 | "browserslist": { 29 | "production": [ 30 | ">0.2%", 31 | "not dead", 32 | "not op_mini all" 33 | ], 34 | "development": [ 35 | "last 1 chrome version", 36 | "last 1 firefox version", 37 | "last 1 safari version" 38 | ] 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/react/app/public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/suoyuesmile/suo-blog/6068b6934e0bcae9b189fcefdc6a6d3752295a29/src/react/app/public/favicon.ico -------------------------------------------------------------------------------- /src/react/app/public/logo192.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/suoyuesmile/suo-blog/6068b6934e0bcae9b189fcefdc6a6d3752295a29/src/react/app/public/logo192.png -------------------------------------------------------------------------------- /src/react/app/public/logo512.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/suoyuesmile/suo-blog/6068b6934e0bcae9b189fcefdc6a6d3752295a29/src/react/app/public/logo512.png -------------------------------------------------------------------------------- /src/react/app/public/manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "short_name": "React App", 3 | "name": "Create React App Sample", 4 | "icons": [ 5 | { 6 | "src": "favicon.ico", 7 | "sizes": "64x64 32x32 24x24 16x16", 8 | "type": "image/x-icon" 9 | }, 10 | { 11 | "src": "logo192.png", 12 | "type": "image/png", 13 | "sizes": "192x192" 14 | }, 15 | { 16 | "src": "logo512.png", 17 | "type": "image/png", 18 | "sizes": "512x512" 19 | } 20 | ], 21 | "start_url": ".", 22 | "display": "standalone", 23 | "theme_color": "#000000", 24 | "background_color": "#ffffff" 25 | } 26 | -------------------------------------------------------------------------------- /src/react/app/public/robots.txt: -------------------------------------------------------------------------------- 1 | # https://www.robotstxt.org/robotstxt.html 2 | User-agent: * 3 | Disallow: 4 | -------------------------------------------------------------------------------- /src/react/app/src/antd-mobile/input.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import './steps-demo.scss' 3 | import { InputItem } from 'antd-mobile'; 4 | 5 | export default InputItem() { 6 | state = { 7 | value: '' 8 | }; 9 | 10 | render() { 11 | return
      12 | 13 |
      14 | } 15 | } -------------------------------------------------------------------------------- /src/react/app/src/antd-mobile/steps-demo.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import './steps-demo.scss' 3 | import { Steps } from 'antd-mobile' 4 | 5 | const Step = Steps.Step; 6 | export default class StepsDemo extends React.Component { 7 | render() { 8 | return
      9 | 10 | 11 | 12 | 13 | 14 |
      15 | } 16 | } -------------------------------------------------------------------------------- /src/react/app/src/antd-mobile/steps-demo.scss: -------------------------------------------------------------------------------- 1 | .am-steps-item-finish .am-steps-item-tail:after { 2 | top: -6px; 3 | height: calc(100% + 10px); 4 | background-color: #888888; 5 | } -------------------------------------------------------------------------------- /src/react/app/src/antd/searchDemo.js: -------------------------------------------------------------------------------- 1 | import React from 'react' 2 | import { Input } from 'antd' 3 | 4 | export default function ImagePickerDemo() { 5 | onChange = () => { 6 | console.log() 7 | } 8 | render() { 9 | return ( 10 | 13 | ) 14 | } 15 | } -------------------------------------------------------------------------------- /src/react/app/src/assets/font/PingFangSC-Regular.fft: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/suoyuesmile/suo-blog/6068b6934e0bcae9b189fcefdc6a6d3752295a29/src/react/app/src/assets/font/PingFangSC-Regular.fft -------------------------------------------------------------------------------- /src/react/app/src/assets/scss/font.scss: -------------------------------------------------------------------------------- 1 | /*声明 WebFont*/ 2 | @font-face { 3 | font-family: 'PingFangSC'; 4 | src: url('../font/PingFangSC-Regular.ttf') format('truetype'); 5 | font-weight: normal; 6 | font-style: normal; 7 | } -------------------------------------------------------------------------------- /src/react/app/src/components/count-down.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | const { useState, useEffect } = React; 3 | 4 | export default function CountDown(props) { 5 | const [timecount, clearTimeCount] = useState(60); 6 | 7 | useEffect(() => { 8 | const timer = setTimeout(() => { 9 | clearTimeCount(timecount - 1) 10 | }, 1000); 11 | if (timecount <= 0) { 12 | clearTimeout(timer); 13 | } 14 | }); 15 | 16 | return
      17 |
      18 | {timecount} 19 |
      20 | 23 |
      24 | } -------------------------------------------------------------------------------- /src/react/app/src/font/pingfangsc-demo.js: -------------------------------------------------------------------------------- 1 | import React from 'react' 2 | 3 | export default function PingFangScDemo() { 4 | return ( 5 |
      6 |
      7 | 测试test 8 | 邵锁 9 |
      10 |
      11 | 测试test 12 | 邵锁 13 |
      14 |
      15 | ) 16 | } -------------------------------------------------------------------------------- /src/react/app/src/index.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import ReactDOM from 'react-dom'; 3 | import RouterDOM from './router/index' 4 | import { BrowserRouter as Router, Route} from 'react-router-dom'; 5 | 6 | import * as serviceWorker from './serviceWorker'; 7 | import 'antd-mobile/dist/antd-mobile.css'; 8 | ReactDOM.render( 9 | 10 | 11 | , 12 | document.getElementById('root') 13 | ); 14 | 15 | // If you want your app to work offline and load faster, you can change 16 | // unregister() to register() below. Note this comes with some pitfalls. 17 | // Learn more about service workers: https://bit.ly/CRA-PWA 18 | serviceWorker.unregister(); 19 | -------------------------------------------------------------------------------- /src/react/app/src/paratice/hook.js: -------------------------------------------------------------------------------- 1 | import React, { useState, useEffect } from 'react'; 2 | 3 | export default class Hook extends React.Component { 4 | render() { 5 | return
      6 | 7 |
      8 | } 9 | } 10 | 11 | // useState & useEffect 12 | // 它类似 class 组件的 this.setState,但是它不会把新的 state 和旧的 state 进行合并 13 | function HookExample() { 14 | const [count, setCount] = useState(0); 15 | useEffect(() => { 16 | document.title = `you clicked ${count}`; 17 | }) 18 | return
      19 |

      {count}

      20 | 21 |
      22 | } 23 | 24 | // todo 自定义hook 25 | 26 | -------------------------------------------------------------------------------- /src/react/app/src/paratice/index.css: -------------------------------------------------------------------------------- 1 | body { 2 | margin: 0; 3 | font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', 4 | 'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue', 5 | sans-serif; 6 | -webkit-font-smoothing: antialiased; 7 | -moz-osx-font-smoothing: grayscale; 8 | } 9 | 10 | code { 11 | font-family: source-code-pro, Menlo, Monaco, Consolas, 'Courier New', 12 | monospace; 13 | } 14 | -------------------------------------------------------------------------------- /src/react/app/src/paratice/lasy-compontent.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | 3 | export default function LasyCompontent() { 4 | return

      lazy import

      ; 5 | } -------------------------------------------------------------------------------- /src/react/app/src/redux.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/suoyuesmile/suo-blog/6068b6934e0bcae9b189fcefdc6a6d3752295a29/src/react/app/src/redux.js -------------------------------------------------------------------------------- /src/react/app/src/router/index.scss: -------------------------------------------------------------------------------- 1 | .menu { 2 | width: 370px; 3 | overflow: hidden; 4 | &__item { 5 | color: #000; 6 | padding: 8px; 7 | display: inline-block; 8 | height: 24px; 9 | line-height: 24px; 10 | // width: 100px; 11 | list-style: none; 12 | } 13 | } -------------------------------------------------------------------------------- /src/react/app/src/setupTests.js: -------------------------------------------------------------------------------- 1 | // jest-dom adds custom jest matchers for asserting on DOM nodes. 2 | // allows you to do things like: 3 | // expect(element).toHaveTextContent(/react/i) 4 | // learn more: https://github.com/testing-library/jest-dom 5 | import '@testing-library/jest-dom/extend-expect'; 6 | -------------------------------------------------------------------------------- /src/react/demo.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Document 6 | 7 | 8 |
      9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /src/react/demo.jsx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/suoyuesmile/suo-blog/6068b6934e0bcae9b189fcefdc6a6d3752295a29/src/react/demo.jsx -------------------------------------------------------------------------------- /src/typescript/js/demo.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | console.log('测试'); 3 | -------------------------------------------------------------------------------- /src/typescript/js/fn-demo.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | function add(num1, num2) { 3 | return num1 + num2; 4 | } 5 | var mob = function (num1, num2) { 6 | return num1 - num2; 7 | }; 8 | // 可选参数必须在最后 9 | var personInfo = function (name, age) { 10 | if (!age) { 11 | return name; 12 | } 13 | return name + age; 14 | }; 15 | // 默认参数 16 | var personInfo2 = function (name, age) { 17 | if (name === void 0) { name = 'shaosuo'; } 18 | if (!age) { 19 | return name; 20 | } 21 | return name + age; 22 | }; 23 | // 剩余参数 24 | var personInfo3 = function (name, age) { 25 | if (name === void 0) { name = 'shaosuo'; } 26 | var result = []; 27 | for (var _i = 2; _i < arguments.length; _i++) { 28 | result[_i - 2] = arguments[_i]; 29 | } 30 | if (!age) { 31 | return name; 32 | } 33 | return name + age; 34 | }; 35 | // 函数重载 同名不同参数类型 36 | // 箭头函数与es6一样 37 | -------------------------------------------------------------------------------- /src/typescript/js/function-demo.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | function add(num1, num2) { 3 | return num1 + num2; 4 | } 5 | var mob = function (num1, num2) { 6 | return num1 - num2; 7 | }; 8 | // 可选参数必须在最后 9 | var personInfo = function (name, age) { 10 | if (!age) { 11 | return name; 12 | } 13 | return name + age; 14 | }; 15 | // 默认参数 16 | var personInfo2 = function (name, age) { 17 | if (name === void 0) { name = 'shaosuo'; } 18 | if (!age) { 19 | return name; 20 | } 21 | return name + age; 22 | }; 23 | // 剩余参数 24 | var personInfo3 = function (name, age) { 25 | if (name === void 0) { name = 'shaosuo'; } 26 | var result = []; 27 | for (var _i = 2; _i < arguments.length; _i++) { 28 | result[_i - 2] = arguments[_i]; 29 | } 30 | if (!age) { 31 | return name; 32 | } 33 | return name + age; 34 | }; 35 | // 函数重载 同名不同参数类型 36 | // 箭头函数与es6一样 37 | -------------------------------------------------------------------------------- /src/typescript/js/interface-demo.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | var somePersonInfo = { 3 | name: 'shao', 4 | age: 12, 5 | gender: 'man' 6 | }; 7 | function ajax(config) { 8 | var xhr = new XMLHttpRequest; 9 | xhr.open(config.type, config.url, true); 10 | xhr.send(config.data); 11 | } 12 | var run = function (key, value) { return ''; }; 13 | var users = []; 14 | var users2 = {}; 15 | var PersonClass = /** @class */ (function () { 16 | function PersonClass() { 17 | this.name = ''; 18 | } 19 | PersonClass.prototype.run = function () { 20 | return 'run'; 21 | }; 22 | return PersonClass; 23 | }()); 24 | var ChildClass = /** @class */ (function () { 25 | function ChildClass(name) { 26 | this.name = name; 27 | } 28 | ChildClass.prototype.run = function () { 29 | return 'run'; 30 | }; 31 | ChildClass.prototype.cry = function () { 32 | return 'wawwaaw'; 33 | }; 34 | return ChildClass; 35 | }()); 36 | -------------------------------------------------------------------------------- /src/typescript/js/overload-demo.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | function overload(a) { 3 | return "overload1 test: " + a; 4 | } 5 | overload(1, 'a'); 6 | -------------------------------------------------------------------------------- /src/typescript/js/type-demo.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | var flag = true; 3 | var str = 'i am god'; 4 | var undefined0 = undefined; 5 | var num = undefined; 6 | var arr = [1, 3, 4]; 7 | var arr2 = [2, 4, 3]; 8 | var tuple = ['123', 3434]; 9 | var Flag; 10 | (function (Flag) { 11 | Flag[Flag["success"] = 1] = "success"; 12 | Flag[Flag["error"] = 2] = "error"; 13 | })(Flag || (Flag = {})); 14 | var a; 15 | -------------------------------------------------------------------------------- /src/typescript/js/type-inference-demo.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | var ab = '123'; 3 | -------------------------------------------------------------------------------- /src/typescript/ts/class-demo.ts: -------------------------------------------------------------------------------- 1 | // 创建 2 | class Person { 3 | name: string; 4 | constructor(name: string) { 5 | this.name = name; 6 | } 7 | run(): string { 8 | return this.name + 'run'; 9 | } 10 | } 11 | 12 | var somePerson = new Person('shaosuo'); 13 | somePerson.run(); 14 | 15 | // 继承 16 | class Child extends Person { 17 | constructor(name: string) { 18 | super(name) 19 | } 20 | study(): string { 21 | return this.name + 'study'; 22 | } 23 | } 24 | 25 | var child = new Child('shaosuo'); 26 | child.study(); 27 | 28 | 29 | // 静态属性和方法 30 | // 创建 31 | class Person2 { 32 | name: string; 33 | constructor(name: string) { 34 | this.name = name; 35 | } 36 | static type = 'animal'; 37 | static active() { 38 | // 不能调用非静态属性和方法 39 | return this.type + 'active'; 40 | } 41 | run(): string { 42 | return this.name + 'run'; 43 | } 44 | } 45 | 46 | console.log(Person2.active()); 47 | 48 | // 多态,继承 49 | 50 | // 抽象类 51 | // 不能被实例,含有抽象方法,子类不含抽象方法的可以被实例。子类必须要实现抽象方法 52 | abstract class Animal { 53 | run(): string { 54 | return 'run'; 55 | } 56 | abstract eat(): string; 57 | } 58 | 59 | class Cat extends Animal { 60 | eat(): string { 61 | return 'eat fish'; 62 | } 63 | } 64 | var cat = new Cat(); 65 | cat.eat(); 66 | 67 | -------------------------------------------------------------------------------- /src/typescript/ts/decorators-demo.ts: -------------------------------------------------------------------------------- 1 | // 装饰器函数 2 | function Age(v: number) { 3 | return function (constructor: T): T { 4 | class PersonAge extends constructor { 5 | age: number = v 6 | } 7 | return PersonAge; 8 | } 9 | } 10 | 11 | @Age(1) 12 | class CatCat { 13 | name = 'cat'; 14 | } 15 | 16 | var catcat = new CatCat(); 17 | console.log(catcat); -------------------------------------------------------------------------------- /src/typescript/ts/demo.ts: -------------------------------------------------------------------------------- 1 | console.log('测试'); -------------------------------------------------------------------------------- /src/typescript/ts/function-demo.ts: -------------------------------------------------------------------------------- 1 | function add(num1: number, num2: number): number { 2 | return num1 + num2; 3 | } 4 | 5 | var mob = (num1: number, num2: number): number => { 6 | return num1 - num2; 7 | } 8 | 9 | // 可选参数必须在最后 10 | var personInfo = (name: string, age?: number) => { 11 | if (!age) { 12 | return name; 13 | } 14 | return name + age; 15 | } 16 | 17 | // 默认参数 18 | var personInfo2 = (name: string = 'shaosuo', age?: number) => { 19 | if (!age) { 20 | return name; 21 | } 22 | return name + age; 23 | } 24 | 25 | // 剩余参数 26 | var personInfo3 = (name: string = 'shaosuo', age: number, ...result: any[]) => { 27 | if (!age) { 28 | return name; 29 | } 30 | return name + age; 31 | } 32 | 33 | // 函数重载 同名不同参数类型 34 | // 箭头函数与es6一样 -------------------------------------------------------------------------------- /src/typescript/ts/generics-demo.ts: -------------------------------------------------------------------------------- 1 | // 范型函数 2 | function getData1(val: string): string { 3 | return val; 4 | } 5 | 6 | function getData2(val: number): number { 7 | return val; 8 | } 9 | 10 | function getData(val: T): T { 11 | return val; 12 | } 13 | getData(123); 14 | 15 | // 范型类 16 | class PersonAny { 17 | constructor(name: T, age: T) { 18 | this.name = name; 19 | this.age = age; 20 | } 21 | name: T; 22 | age: T; 23 | run(val: T): T { 24 | return val; 25 | }; 26 | } 27 | var somePerson1 = new PersonAny('shao', '12'); 28 | 29 | // 范型接口 30 | 31 | // 属性范型接口 32 | interface PersonInfoAny { 33 | (name:T):T; 34 | age: string; 35 | } 36 | 37 | interface PersonInfoAny2 { 38 | (name: T): T; 39 | age: string; 40 | } 41 | 42 | // 类范型接口 43 | interface PersonInterfaceAny { 44 | name: T; 45 | run(val: T): T; 46 | } 47 | 48 | class PersonClassAny implements PersonInterfaceAny { 49 | name: string; 50 | constructor(name: string) { 51 | this.name = name; 52 | } 53 | run(val: string) { 54 | return val + '...'; 55 | } 56 | } 57 | 58 | var somePerson2 = new PersonClassAny('shaosuo'); -------------------------------------------------------------------------------- /src/typescript/ts/overload-demo.ts: -------------------------------------------------------------------------------- 1 | function overload(a: number): string; 2 | function overload(a: string): string; 3 | function overload(a: number, b: string): string; 4 | function overload(a: any): string { 5 | return `overload1 test: ${a}` 6 | } 7 | 8 | 9 | overload(1, 'a') -------------------------------------------------------------------------------- /src/typescript/ts/type-advanced-demo.ts: -------------------------------------------------------------------------------- 1 | // 交叉类型 2 | function extend(first: T, second: U): T & U { 3 | let result = {}; 4 | for(let id in first) { 5 | (result)[id] = (first)[id]; 6 | } 7 | for(let id in second) { 8 | if (!(result).hasOwnProperty(id)) { 9 | (result)[id] = (second)[id]; 10 | } 11 | } 12 | return result; 13 | } 14 | 15 | class PersonIntersect { 16 | constructor(public name: string) {} 17 | } 18 | interface Loggable { 19 | log(): void; 20 | } 21 | class ConsoleLoggable implements Loggable { 22 | log() { 23 | console.log('log'); 24 | } 25 | } 26 | 27 | var shao = extend(new PersonIntersect('name'), new ConsoleLoggable()); 28 | 29 | // 联合类型 30 | // 类型守卫 31 | // 类型别名 -------------------------------------------------------------------------------- /src/typescript/ts/type-demo.ts: -------------------------------------------------------------------------------- 1 | var flag: boolean = true; 2 | 3 | var str: string = 'i am god'; 4 | 5 | var undefined0: undefined = undefined; 6 | 7 | var num: number | undefined = undefined; 8 | 9 | var arr: number[] = [1, 3, 4]; 10 | var arr2: Array = [2, 4, 3]; 11 | 12 | var tuple: [string, number] = ['123', 3434]; 13 | 14 | enum Flag { 15 | success = 1, 16 | error = 2 17 | } 18 | 19 | var a: never; 20 | -------------------------------------------------------------------------------- /src/typescript/ts/type-inference-demo.ts: -------------------------------------------------------------------------------- 1 | let ab = '123'; 2 | -------------------------------------------------------------------------------- /src/web-api/localstorage.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/suoyuesmile/suo-blog/6068b6934e0bcae9b189fcefdc6a6d3752295a29/src/web-api/localstorage.js -------------------------------------------------------------------------------- /src/web-api/sessionstorage.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/suoyuesmile/suo-blog/6068b6934e0bcae9b189fcefdc6a6d3752295a29/src/web-api/sessionstorage.js -------------------------------------------------------------------------------- /src/webpack/simple-webpack/example/entry.js: -------------------------------------------------------------------------------- 1 | import message from './message.js'; 2 | 3 | console.log(message); -------------------------------------------------------------------------------- /src/webpack/simple-webpack/example/message.js: -------------------------------------------------------------------------------- 1 | import { name } from './name.js' 2 | 3 | export default `hello ${name}`; 4 | 5 | -------------------------------------------------------------------------------- /src/webpack/simple-webpack/example/name.js: -------------------------------------------------------------------------------- 1 | export const name = 'shaosuo'; --------------------------------------------------------------------------------