From d20ef25e32878563c8bc9a37d2c159d11fb7d457 Mon Sep 17 00:00:00 2001 From: cnhacklqr Date: Sun, 17 Dec 2023 15:19:33 +0800 Subject: [PATCH] Update Code --- src/algorithm/sort/bubble/bubble.cpp | 21 ++++++++++ src/algorithm/sort/select/select | Bin 0 -> 16176 bytes src/algorithm/sort/select/select.cpp | 32 +++++++++++++++ src/type/imitate/huanfang.cpp | 34 ++++++++++++++++ src/type/imitate/set | Bin 0 -> 17104 bytes src/type/imitate/set.cpp | 27 +++++++++++++ src/type/vector/intVector.cpp | 52 ------------------------ src/type/vector/intVector.h | 58 ++++++++++++++++++++++++--- 8 files changed, 167 insertions(+), 57 deletions(-) create mode 100644 src/algorithm/sort/bubble/bubble.cpp create mode 100755 src/algorithm/sort/select/select create mode 100644 src/algorithm/sort/select/select.cpp create mode 100644 src/type/imitate/huanfang.cpp create mode 100755 src/type/imitate/set create mode 100644 src/type/imitate/set.cpp delete mode 100644 src/type/vector/intVector.cpp diff --git a/src/algorithm/sort/bubble/bubble.cpp b/src/algorithm/sort/bubble/bubble.cpp new file mode 100644 index 0000000..c152b5c --- /dev/null +++ b/src/algorithm/sort/bubble/bubble.cpp @@ -0,0 +1,21 @@ +#include +#include + +int main(){ + int n,i,j; + std::cin>>n; + int listn[n]; + for(int i=1;i<=n;i++){ + std::cin>>i[listn]; + } + for (i = 1; i <= 1; i++) + { + for (j = 1; j <= i; j++) + { + if(listn[j]>listn[j+true]){ + swap(listn[j],listn[j+1]); + } + } + } + std::cout<6~4QU6Nfsn6CC0uG+E_=k_K=5itA89){k+20cqtzQ6hwhg{Wi`T2fI;0yN7x_nxyJ zk9Mmje?Zk-Yv$bZ-SeG$=iGVR@t*mbw!Ovg^9e2m;xhuZ!BT~UsNvjWQ~?nZ^!_A}?Plov&J03OWwt6=DJVz=^Cl6zDxghP#G6Zc{LUJ#Jn>Ro_w`?YRme>cD_BZUvgY>tXc*OzfM!4k~1q+tk-yYy$ zTs~;wX>Ozb^36jJ#giq@Ht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mode 100644 index 0000000..3ace143 --- /dev/null +++ b/src/algorithm/sort/select/select.cpp @@ -0,0 +1,32 @@ +#include + +int main() +{ + int minIndex, n; + std::cin >> n; + int listn[n]; + for (int i = 0; i < n; i++) + { + std::cin >> listn[i]; + } + for (int i = 0; i < n; i++) + { + minIndex = i; + for (int j = i; j < n; j++) + { + if (listn[minIndex] > listn[j]) + { + minIndex = j; + } + } + int tmp = listn[i]; + listn[i] = listn[minIndex]; + listn[minIndex] = tmp; + } + for (int i = 0; i < n; i++) + { + std::cout << listn[i] << " "; + } + std::cout << std::endl; + return 0; +} \ No newline at end of file diff --git a/src/type/imitate/huanfang.cpp b/src/type/imitate/huanfang.cpp new file mode 100644 index 0000000..40091ad --- /dev/null +++ b/src/type/imitate/huanfang.cpp @@ -0,0 +1,34 @@ +#include +#include +#include + +int main() +{ + int n, x, y, a[40][40]; + memset(a, 0, sizeof(a)); + std::cin >> n; + x = 1, y = (n + 1) / 2; + + for (int i = 1; i <= n * n; i++) + { + a[x][y] = i; + if (!a[(x - 2 + n) % n + 1][y % n + 1]) + { + x = (x - 2 + n) % n + true; + y = y % n + true; + } + else + { + x = x % n + true; + } + } + + for (int i = 1; i <= n; i++) + { + for (int j = 1; j <= n; j++) + { + printf("%4d", a[i][j]); + } + printf("\n"); + } +} \ No newline at end of file diff --git a/src/type/imitate/set b/src/type/imitate/set new file mode 100755 index 0000000000000000000000000000000000000000..89c20bb23c24bab8c500d9acb7cef39b0b8c620d GIT binary patch literal 17104 zcmeHO4RBP~b-ueuM*K?HU=v8fg0Tz5EcyW=>{71~4?j786(l9(hdh?uMcN?k%DYb> zF}T%qvE$8JGt`s#C-F>Ow@qdmr*RXKVI0>H76su^J;J6b>A0ei#&46c>UVsLXlozi&;$e_@s<06>! zp3-_xX+5SjT8}B`lX60zMxD<>8bBMBfczGsP_JL>71FI*o+h2Wlx}*Cxu3y(3UfUgw_4TjqZ``0R{5 z+-3`*iowsu95eLYByyqx_}isUe{h&80s+7qO!wxY>+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>L7LO0KFCC&XLC~ik@h2 zhtLQQ`;tjkf0wftZl`pRU^;0VdJ`D%hCU6VJAXY+TTs_ei+!XsVz=R-gh9tR+y^6a z7mec##k$ZHFWPfQNb+Ee3wh+k9p$^9Y{@&z5#W;*d}1ZvPLTsMB@V^#*xwLI;Pgt~ z^*7gn75?Nvj~(0xY9|!!;u_5wiC*E4#qEf{GuG$tO~i53#U5}$`}(3dxE2j-2uC^A z+QCjC#k+#ZF5wRk#Na|vJE2+*;=l}@t&w7yvCx)?bO%X6*Lu5c;g`eCZ%6u3m$!~T z5tmbdKhkCGPXv1+R#zCh%)uy*s;Kij7On_4uC$>J(kL5TCp+X6CS`!Zo@faAak#>l zU;0TfrMpWGT{aT+XKX+LkkDa{I0?w`fnAT_N%afk|-N^7KP{ChcagLwYaZGEq zAg|*J;}4>p)^M!P>pZ5bbOXgmd1ifH?_u!EH6H8px{)cb6CoxG*>IP;!O)tF^?4n} zly=in;rLmO>7SsD)_BbGI*;kN)K)pB)N=e97DK2|pRhi!Gnx8y!0ey(`T8H$`dhR? zxsw@nrfz*&s~773B`|Wq_H(~O^$#;%&qG9(!twJMP`AEM>oMi)*Xo7l#n%e-`S&-| z>#5^iMVrqd-$2dnpVt9Q=j9|-r7-?)YkkhY@M#52Z`3T4LjCWdf&8;RulJa?v!bSj z`ezID`+Z7~X)hUf74AQVUP8s~Kf7GDFx5XhSzOBI7*t-tXFfjqw$GhQ1t?y$+O<9lO*-)mj%lf>o=JW7;?wyAb z>+?9e4*G8Ye4cK2o$|1X9cjw?OzB*#Tc6)EWwn0)d+0AO(BB(S3VUl6<@=n?uwUl? z0Q!XS^$!MAOTX3+@W9jxx><8V+@k$!@f^lY{#u;RY}>lmkm literal 0 HcmV?d00001 diff --git a/src/type/imitate/set.cpp b/src/type/imitate/set.cpp new file mode 100644 index 0000000..45b6831 --- /dev/null +++ b/src/type/imitate/set.cpp @@ -0,0 +1,27 @@ +#include +#include "../vector/intVector.h" + +int main() +{ + int n, k, num; + std::cin >> n >> k; + vector *listn = new vector(n); + for (int i = 0; i < n; i++) + { + int tmp; + scanf("&d",&tmp); + listn->append(tmp); + } + + for (int i = 0; i < n; i++) + { + for (int j = i; j < n; j++) + { + if ((listn->read(j)%listn->read(i))!=0){ + listn->erase(n); + } + } + } + std::cout<getSize(); + return 0; +} \ No newline at end of file diff --git a/src/type/vector/intVector.cpp b/src/type/vector/intVector.cpp deleted file mode 100644 index a01db90..0000000 --- a/src/type/vector/intVector.cpp +++ /dev/null @@ -1,52 +0,0 @@ -#include "intVector.h" - -int vector::append(int number) -{ - int tmp[size++]; - for (int i = 0; i < size - 1; i++) - { - tmp[i] = this->list[i]; - } - this->list = new int[size]; - for (int i = 0; i < size - 1; i++) - { - this->list[i] = tmp[i]; - } - this->list[size - 1] = number; - return 0; -} - -int vector::print(const char *end) -{ - for (int i = 0; i < size; i++) - { - std::cout << this->list[i]; - } - std::cout << end; - return 0; -} - -int vector::erase(int index) -{ - if (index >= size || index < 0) - { - throw "Index is so big or small"; - return -1; - } - this->list[index] = 0; - for (int i = index + 1; i < size; i++) - { - this->list[i - 1] = this->list[i]; - } - int tmp[size--]; - for (int i = 0; i < size; i++) - { - tmp[i] = this->list[i]; - } - this->list = new int[size]; - for (int i = 0; i < size; i++) - { - this->list[i] = tmp[i]; - } - return 0; -} \ No newline at end of file diff --git a/src/type/vector/intVector.h b/src/type/vector/intVector.h index 756b9c2..b10b8f2 100644 --- a/src/type/vector/intVector.h +++ b/src/type/vector/intVector.h @@ -5,14 +5,10 @@ class vector { public: - vector(int size, int *list) + vector(int size) { this->size = size; this->list = new int[size]; - for (int i = 0; i < size; i++) - { - this->list[i] = list[i]; - } } int append(int); @@ -21,9 +17,61 @@ public: int read(int index) { return this->list[index]; } int print(const char *); int erase(int index); + int getSize(){ return this->size; }; private: int size; int *list; }; + +int vector::append(int number) +{ + int tmp[size++]; + for (int i = 0; i < size - 1; i++) + { + tmp[i] = this->list[i]; + } + this->list = new int[size]; + for (int i = 0; i < size - 1; i++) + { + this->list[i] = tmp[i]; + } + this->list[size - 1] = number; + return 0; +} + +int vector::print(const char *end) +{ + for (int i = 0; i < size; i++) + { + std::cout << this->list[i]; + } + std::cout << end; + return 0; +} + +int vector::erase(int index) +{ + if (index >= size || index < 0) + { + throw "Index is so big or small"; + return -1; + } + this->list[index] = 0; + for (int i = index + 1; i < size; i++) + { + this->list[i - 1] = this->list[i]; + } + int tmp[size--]; + for (int i = 0; i < size; i++) + { + tmp[i] = this->list[i]; + } + this->list = new int[size]; + for (int i = 0; i < size; i++) + { + this->list[i] = tmp[i]; + } + return 0; +} #endif \ No newline at end of file