From 71e877823529664e40ae78427001b3944ecf6035 Mon Sep 17 00:00:00 2001 From: Lake Hoo Date: Tue, 30 Mar 2021 18:31:19 +0800 Subject: [PATCH 01/89] new version --- SuperPrime.cpp | 104 +++++++++++++++---------------------------------- 1 file changed, 32 insertions(+), 72 deletions(-) diff --git a/SuperPrime.cpp b/SuperPrime.cpp index 44e04a7c..297f605e 100644 --- a/SuperPrime.cpp +++ b/SuperPrime.cpp @@ -1,81 +1,41 @@ -class Number { +#include +class Nature { +private: + int num; //数 public: - Number(int num):mNum(num) { - } - Number(const Number &n):mNum(n.mNum) { - } - ~Number(); - NumberSet split() { - NumberSet ns; - int n = mNum; - while(n != 0) { - int d = n % 10; - Number dig(d); - ns.add(dig); - n = n / 10; - } - return ns; - } - bool isPrime() { - for(int i = 2; i < mNum; ++i) { - if(mNum % i == 0) - break; - } - if(i != mNum) - return false; - return true; + Nature(); + ~Nature(); + Nature add(Nature sp); //求和 + bool compare(Nature sp) { //比大小 + if(num > sp.num) + return true; + return false; } -private: - const int mNum; + }; -class NumberSet { -private: - Number *nums[20]; - int size; +class SuperPrime { +private: + const unsigned int num; //数 public: - NumberSet() { - size = 0; - for(int i = 0; i < 20; ++i) - nums[i] = NULL; + SuperPrime(int n):num(n) { } - ~NumberSet() { - for(int i = 0; i < size; ++i) - delete nums[i]; + ~SuperPrime() { } - bool add(const Number &n) { - if(size != 20 && nums[size] == NULL) { - nums[size] = new Number(n); - size += 1; - return true; - } + Nature add(SuperPrime sp) { //求和 + return Nature(num + sp.num); + } + bool compare(SuperPrime sp) { //比大小 + if(num > sp.num) + return true; return false; } - Number sum() { - Number sum(0); - for(int i = 0; i < size; ++i) { - if(nums[i] != NULL) - sum.add(*(nums[i])); - } - return sum; - } }; -class SuperPrime : public Number { -public: - SuperPrime(int num); - ~SuperPrime(); - - bool isPrime(); - - Prime sumBit(); - Prime multiBit(); - Prime sqaureSumBit(); -private: - const int num; -} -int main() -{ - SuperPrime sp(113); - if(sp.isPrime()) { - ; // do something - } -} +int main() { + Nature sum(0); + for(int i = 100; i < 999; i++) { + Nature sp1(i); + if ( sp1.isPrime() ) + sum = sum.add(sp1); + } + return 0; +} From c1ad70fb53560f83cc598d61fe214921714f18f4 Mon Sep 17 00:00:00 2001 From: Lake Hu Date: Fri, 2 Apr 2021 10:12:43 +0800 Subject: [PATCH 02/89] Create c-cpp.yml MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 绗竴娆℃祴璇 --- .github/workflows/c-cpp.yml | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 .github/workflows/c-cpp.yml diff --git a/.github/workflows/c-cpp.yml b/.github/workflows/c-cpp.yml new file mode 100644 index 00000000..89207f5c --- /dev/null +++ b/.github/workflows/c-cpp.yml @@ -0,0 +1,21 @@ +name: C/C++ CI + +on: + push: + branches: [ master ] + pull_request: + branches: [ master ] + +jobs: + build: + + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + - name: make + run: make + - name: make check + run: make check + - name: make distcheck + run: make distcheck From 6994e9c7ecc07c38e39dbbd032d9941800aeb969 Mon Sep 17 00:00:00 2001 From: Lake Hoo Date: Fri, 2 Apr 2021 10:17:40 +0800 Subject: [PATCH 03/89] testing for Github workflow --- Makefile | 1 + 1 file changed, 1 insertion(+) create mode 100644 Makefile diff --git a/Makefile b/Makefile new file mode 100644 index 00000000..590d1e79 --- /dev/null +++ b/Makefile @@ -0,0 +1 @@ +$(CXX) main.cpp -o main \ No newline at end of file From 5d04d8715bc179e5b52b53df4d1ceb3d31ff2541 Mon Sep 17 00:00:00 2001 From: Lake Hoo Date: Fri, 2 Apr 2021 10:26:43 +0800 Subject: [PATCH 04/89] try to testing for Github workflow --- Makefile | 3 ++- main.cpp | 8 +++++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 590d1e79..d8789745 100644 --- a/Makefile +++ b/Makefile @@ -1 +1,2 @@ -$(CXX) main.cpp -o main \ No newline at end of file +main:main.cpp + $(CXX) main.cpp -o main \ No newline at end of file diff --git a/main.cpp b/main.cpp index 91307286..fec95e9b 100644 --- a/main.cpp +++ b/main.cpp @@ -1,4 +1,10 @@ -#include "HelloWorld.h" +class HelloWorld { +public: + HelloWorld() { + } + void hello() { + } +}; int main() { HelloWorld hw; hw.hello(); From cf5814ce57d6dc69e45e8ac66c7b6179aa4b1feb Mon Sep 17 00:00:00 2001 From: Lake Hoo Date: Fri, 2 Apr 2021 10:41:03 +0800 Subject: [PATCH 05/89] try to testing Github workflow --- Makefile | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index d8789745..06fcb64d 100644 --- a/Makefile +++ b/Makefile @@ -1,2 +1,7 @@ main:main.cpp - $(CXX) main.cpp -o main \ No newline at end of file + $(CXX) main.cpp -o main + +check: + cppcheck main.cpp + +distcheck: From f349aead81a85b4cd9835d92e5344f7411f287d9 Mon Sep 17 00:00:00 2001 From: Lake Hoo Date: Fri, 2 Apr 2021 10:51:02 +0800 Subject: [PATCH 06/89] try to test Github workflow --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 06fcb64d..90a6cd2e 100644 --- a/Makefile +++ b/Makefile @@ -2,6 +2,6 @@ main:main.cpp $(CXX) main.cpp -o main check: - cppcheck main.cpp + distcheck: From d22ab8321e6b6dbee35466dcd2f73e998770a7fc Mon Sep 17 00:00:00 2001 From: Lake Hoo Date: Fri, 2 Apr 2021 10:58:32 +0800 Subject: [PATCH 07/89] add Cppcheck action --- .github/workflows/c-cpp.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/c-cpp.yml b/.github/workflows/c-cpp.yml index 89207f5c..0e7dfa9e 100644 --- a/.github/workflows/c-cpp.yml +++ b/.github/workflows/c-cpp.yml @@ -13,6 +13,8 @@ jobs: steps: - uses: actions/checkout@v2 + - name: cppcheck-action + uses: deep5050/cppcheck-action@v2.0.0 - name: make run: make - name: make check From 1f005057be61ca7fb509e33ce8762585fcabb958 Mon Sep 17 00:00:00 2001 From: Biuviu <33221210+Biuviu@users.noreply.github.com> Date: Fri, 2 Apr 2021 11:01:10 +0800 Subject: [PATCH 08/89] Update main.cpp --- main.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/main.cpp b/main.cpp index 91307286..f473f3bb 100644 --- a/main.cpp +++ b/main.cpp @@ -1,6 +1,8 @@ #include "HelloWorld.h" int main() { HelloWorld hw; + HelloWorld w; hw.hello(); + w.hello(); return 0; } From 51680d452a349738a926f913e65126fce5eff2a5 Mon Sep 17 00:00:00 2001 From: Lake Hoo Date: Fri, 2 Apr 2021 11:13:05 +0800 Subject: [PATCH 09/89] first homework --- Makefile | 5 +++++ SuperPrime_HW.cpp | 5 +++++ 2 files changed, 10 insertions(+) create mode 100644 SuperPrime_HW.cpp diff --git a/Makefile b/Makefile index 90a6cd2e..49e28f73 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,11 @@ +all: main sp + main:main.cpp $(CXX) main.cpp -o main +sp:SuperPrime_HW.cpp + $(CXX) SuperPrime_HW.cpp -o sp + check: diff --git a/SuperPrime_HW.cpp b/SuperPrime_HW.cpp new file mode 100644 index 00000000..0e004b50 --- /dev/null +++ b/SuperPrime_HW.cpp @@ -0,0 +1,5 @@ +#include + +int main() { + return 0; +} From 75bcbd192c19dc1a7c28d9fd3f9af10194d06747 Mon Sep 17 00:00:00 2001 From: Lake Hoo Date: Tue, 6 Apr 2021 17:10:45 +0800 Subject: [PATCH 10/89] =?UTF-8?q?=E6=9E=84=E9=80=A0=E5=87=BD=E6=95=B0?= =?UTF-8?q?=E5=A5=BD=E5=90=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SuperPrime2.cpp | 166 ++++++++++++++---------------------------------- 1 file changed, 46 insertions(+), 120 deletions(-) diff --git a/SuperPrime2.cpp b/SuperPrime2.cpp index 1f7d28d7..9684f52e 100644 --- a/SuperPrime2.cpp +++ b/SuperPrime2.cpp @@ -1,124 +1,50 @@ -//作业:面向对象设计以下框架的代码细节,程序能编译运行得到正确结果 #include -class Prime { - public: - Prime():number(0) { - } - Prime(int n):number(n) { - } - ~Prime() { - } - bool isPrime() { - //2到number-1的因子 - return false; - } - private: - const int number; -}; -class PrimeSet { - public: - PrimeSet(int size) { - //集合的构造什么? - N = new Prime*[size]; - this->size = size; - index = 0; - } - ~PrimeSet() { - for (int i = 0; i < index; ++i) //销毁对象 - delete N[i]; - delete[] N; - } - bool add(int n) { - if(index == size) return false; - Prime *p = new Prime(n); - N[index] = p; - index += 1; - return true; - } - bool isAllPrime() { - for(int i = 0; i < index; i++) - if (!N[i]->isPrime()) - return false; - return true; - } - private: - Prime **N; - int size, index; -}; class SuperPrime { - public: - SuperPrime():number(0), pset(3) { //为什么必须有? - } - SuperPrime(int n):number(n), pset(3) { - split(); //它就是构造对象 - } - ~SuperPrime() { - } - bool isSuperPrime() { - //怎么使用pset? - Prime p(number); - if (p.isPrime()) - return true; - return false; - } - private: - const int number; - PrimeSet pset; - void split() { //工厂方法设计模式 - // number split into N - int temp = number; - while(temp > 0) { - int n = temp % 10; - temp /= 10; - pset.add(n); //作业:单个数字为对象?还是和/积/平方和为对象? - } - } - int sum() { - return 0; - } - int multi() { - return 0; - } - int squareSum() { - return 0; - } -}; -class SuperPrimeSet { - public: - SuperPrimeSet(int from, int to) { - size = to - from; - for (int i = from; i < to; i++) - set[i-from] = new SuperPrime(i); - } - ~SuperPrimeSet() { - for(int i = 0; i < size; i++) - delete set[i]; - } - int count() { - int count = 0; - for (int i = 0; i < size; i++) - if(set[i]->isSuperPrime()) - count += 1; - return count; - } - int sum() { - int sum = 0; - /* - for (int i = 0; i < size; i++) - if(set[i].isSuperPrime()) - sum += set[i]; - */ - return sum; - } - private: - SuperPrime **set; - int size, index; +private: + const int left, right; +public: + SuperPrime(int a, int b):left(a), right(b) { + } + + + + + + + + + + + + + + int max() { + return 0; + } + int howmany() { + return 0; + } + int sum() { + return 0; + } }; -int main() { - SuperPrime sp(113); - if (sp.isSuperPrime()) - std::cout << "113 is SuperPrime" << std::endl; - else - std::cout << "113 is NOT SuperPrime" << std::endl; + + + + + + + + + + + + +int main() +{ + SuperPrime sp(100, 999); + std::cout << "最大的超级素数:" << sp.max() << std::endl; + std::cout << "超级素数个数:" << sp.howmany() << std::endl; + std::cout << "超级素数的和:" << sp.sum() << std::endl; return 0; -} +} From e4417ff04d4f4af0487cfffe6e144b29e11b14cb Mon Sep 17 00:00:00 2001 From: Lake Hoo Date: Tue, 6 Apr 2021 18:31:10 +0800 Subject: [PATCH 11/89] =?UTF-8?q?=E5=AF=B9=E8=B1=A1=E7=9A=84=E5=AE=B9?= =?UTF-8?q?=E5=99=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SuperPrime2.cpp | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/SuperPrime2.cpp b/SuperPrime2.cpp index 9684f52e..0081e79d 100644 --- a/SuperPrime2.cpp +++ b/SuperPrime2.cpp @@ -5,20 +5,13 @@ class SuperPrime { public: SuperPrime(int a, int b):left(a), right(b) { } - - - - - - - - - - - - - int max() { + //哪个对象做? + for(int x1 = left; x1 < right; x1++) { + split(x1); + //判断素数 + } + return 0; } int howmany() { @@ -27,6 +20,17 @@ class SuperPrime { int sum() { return 0; } +private: + void split(int x) { + int a, sum, mult, sqrsum; + while(x != 0) { + a = x % 10; + sum += a; + mult *= a; + sqrsum += a*a; + x = x / 10; + } + } }; From 0efd0c30cf6419a06e32416f421025a5487e0446 Mon Sep 17 00:00:00 2001 From: Lake Hoo Date: Tue, 6 Apr 2021 18:33:01 +0800 Subject: [PATCH 12/89] =?UTF-8?q?=E5=AF=B9=E8=B1=A1=E7=9A=84=E5=AE=B9?= =?UTF-8?q?=E5=99=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SuperPrime2.cpp | 54 ++++++++++++++++++++++++++++++------------------- 1 file changed, 33 insertions(+), 21 deletions(-) diff --git a/SuperPrime2.cpp b/SuperPrime2.cpp index 0081e79d..122b6bc8 100644 --- a/SuperPrime2.cpp +++ b/SuperPrime2.cpp @@ -1,24 +1,47 @@ #include +#include +class Nature { +private: + const int num; //数 +public: + Nature(int n):num(n) { + } + ~Nature(); + Nature add(Nature sp); //求和 + bool compare(Nature sp) { //比大小 + if(num > sp.num) + return true; + return false; + } + +}; + class SuperPrime { private: - const int left, right; + std::vector range; //超级素数的容器 public: - SuperPrime(int a, int b):left(a), right(b) { + SuperPrime(int a, int b) { + for(int i = a; i < b; i++) { + Nature nat(i); + if(nat.isSuperPrime()) //过滤器 + range.push_back(nat); + } } int max() { - //哪个对象做? - for(int x1 = left; x1 < right; x1++) { - split(x1); - //判断素数 - } - + for(std::vector::iterate it = range.begin(); + it != range.end(); it++) { + if(it->compare()) + } return 0; } + int howmany() { - return 0; + return range.size(); } int sum() { - return 0; + for(std::vector::iterate it = range.begin(); + it != range.end(); it++) { + } } private: void split(int x) { @@ -33,17 +56,6 @@ class SuperPrime { } }; - - - - - - - - - - - int main() { SuperPrime sp(100, 999); From 4f481596daa65b339e64371f6b9487b8ad9f01d1 Mon Sep 17 00:00:00 2001 From: Lake Hoo Date: Tue, 13 Apr 2021 17:02:44 +0800 Subject: [PATCH 13/89] first version --- SuperPrime.cpp | 42 +++++++++++++----------------------------- 1 file changed, 13 insertions(+), 29 deletions(-) diff --git a/SuperPrime.cpp b/SuperPrime.cpp index 297f605e..3cf2a40b 100644 --- a/SuperPrime.cpp +++ b/SuperPrime.cpp @@ -1,41 +1,25 @@ #include +#include class Nature { -private: - int num; //数 +private: + int num; public: - Nature(); - ~Nature(); - Nature add(Nature sp); //求和 - bool compare(Nature sp) { //比大小 - if(num > sp.num) - return true; - return false; + Nature(int n):num(n) { } - }; class SuperPrime { -private: - const unsigned int num; //数 +private: + std::vector natures; public: - SuperPrime(int n):num(n) { - } - ~SuperPrime() { - } - Nature add(SuperPrime sp) { //求和 - return Nature(num + sp.num); - } - bool compare(SuperPrime sp) { //比大小 - if(num > sp.num) - return true; - return false; + SuperPrime(int a, int b) { + //std::cout << "Create SuperPrime from " << a << " to " << b << std::endl; + for(int i = a; i < b; i++) { + Nature nat(i); + natures.push_back(nat); + } } }; int main() { - Nature sum(0); - for(int i = 100; i < 999; i++) { - Nature sp1(i); - if ( sp1.isPrime() ) - sum = sum.add(sp1); - } + SuperPrime sp(100, 999); return 0; } From c27f39558b64897d3b648b34b415e5b25e46973e Mon Sep 17 00:00:00 2001 From: Lake Hoo Date: Tue, 13 Apr 2021 17:17:09 +0800 Subject: [PATCH 14/89] detroyer error --- SuperPrime.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/SuperPrime.cpp b/SuperPrime.cpp index 3cf2a40b..26e1acca 100644 --- a/SuperPrime.cpp +++ b/SuperPrime.cpp @@ -5,6 +5,10 @@ class Nature { int num; public: Nature(int n):num(n) { + std::cout << "Create Nature as " << num << std::endl; + } + ~Nature() { + std::cout << "Destroy Nature as " << num << std::endl; } }; class SuperPrime { @@ -12,7 +16,7 @@ class SuperPrime { std::vector natures; public: SuperPrime(int a, int b) { - //std::cout << "Create SuperPrime from " << a << " to " << b << std::endl; + std::cout << "Create SuperPrime from " << a << " to " << b << std::endl; for(int i = a; i < b; i++) { Nature nat(i); natures.push_back(nat); @@ -20,6 +24,6 @@ class SuperPrime { } }; int main() { - SuperPrime sp(100, 999); + SuperPrime sp(10, 12); return 0; } From 0d5c834ebcfa374881daa9cabe6f27be8b62d000 Mon Sep 17 00:00:00 2001 From: Lake Hoo Date: Tue, 13 Apr 2021 17:27:49 +0800 Subject: [PATCH 15/89] cout some infos --- SuperPrime.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/SuperPrime.cpp b/SuperPrime.cpp index 26e1acca..baf42871 100644 --- a/SuperPrime.cpp +++ b/SuperPrime.cpp @@ -19,9 +19,12 @@ class SuperPrime { std::cout << "Create SuperPrime from " << a << " to " << b << std::endl; for(int i = a; i < b; i++) { Nature nat(i); - natures.push_back(nat); + std::cout << "HAHA" << std::endl; } } + ~SuperPrime() { + std::cout << "Destroy SuperPrime " << std::endl; + } }; int main() { SuperPrime sp(10, 12); From 3225b4861e42bdb37bd0c1022279c794b49cdb7d Mon Sep 17 00:00:00 2001 From: Lake Hoo Date: Tue, 13 Apr 2021 17:38:06 +0800 Subject: [PATCH 16/89] vector to create or destroy object --- SuperPrime.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/SuperPrime.cpp b/SuperPrime.cpp index baf42871..2c23580c 100644 --- a/SuperPrime.cpp +++ b/SuperPrime.cpp @@ -20,6 +20,8 @@ class SuperPrime { for(int i = a; i < b; i++) { Nature nat(i); std::cout << "HAHA" << std::endl; + natures.push_back(nat); + std::cout << "DDDDD" << std::endl; } } ~SuperPrime() { From 2ebfb09466b73dbdc4de0635d81e902e9900ba9d Mon Sep 17 00:00:00 2001 From: Lake Hoo Date: Tue, 13 Apr 2021 18:12:05 +0800 Subject: [PATCH 17/89] version 2 --- SuperPrime.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/SuperPrime.cpp b/SuperPrime.cpp index 2c23580c..5a1b0aaa 100644 --- a/SuperPrime.cpp +++ b/SuperPrime.cpp @@ -4,9 +4,15 @@ class Nature { private: int num; public: + Nature():num(0){ + std::cout << "Default Create Nature as " << num << std::endl; + } Nature(int n):num(n) { std::cout << "Create Nature as " << num << std::endl; } + Nature(const Nature &nat):num(nat.num){ + std::cout << "Copy Create Nature as " << num << std::endl; + } ~Nature() { std::cout << "Destroy Nature as " << num << std::endl; } @@ -29,6 +35,6 @@ class SuperPrime { } }; int main() { - SuperPrime sp(10, 12); + SuperPrime sp(10, 13); return 0; } From 0c6fe07937ee4c12317df9ae56076f9518e3fc81 Mon Sep 17 00:00:00 2001 From: Lake Hoo Date: Tue, 13 Apr 2021 18:26:03 +0800 Subject: [PATCH 18/89] add member function --- SuperPrime.cpp | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/SuperPrime.cpp b/SuperPrime.cpp index 5a1b0aaa..50074af6 100644 --- a/SuperPrime.cpp +++ b/SuperPrime.cpp @@ -33,8 +33,25 @@ class SuperPrime { ~SuperPrime() { std::cout << "Destroy SuperPrime " << std::endl; } + + Nature max() { + std::vector::iterate it = natures.begin(); + Nature max(0); + for(; it != natures.end(); it ++) { + if(it->isSuperPrime()) { + if (max.compare(*it)) { + max = *it; + } + } + } + return max; + } }; int main() { SuperPrime sp(10, 13); + Nature n = sp.max(); + std::cout << "最大超级素数:" ; + n.show(); + return 0; } From 8c2bafe6370898b9f4d3933475c75bee1f2f5cbc Mon Sep 17 00:00:00 2001 From: Dashark Date: Tue, 13 Apr 2021 20:22:04 +0800 Subject: [PATCH 19/89] new homework --- SuperPrime-HW2.cpp | 57 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 SuperPrime-HW2.cpp diff --git a/SuperPrime-HW2.cpp b/SuperPrime-HW2.cpp new file mode 100644 index 00000000..9f16866e --- /dev/null +++ b/SuperPrime-HW2.cpp @@ -0,0 +1,57 @@ +#include +#include +class Nature { +private: + int num; +public: + Nature():num(0){ + std::cout << "Default Create Nature as " << num << std::endl; + } + Nature(int n):num(n) { + std::cout << "Create Nature as " << num << std::endl; + } + Nature(const Nature &nat):num(nat.num){ + std::cout << "Copy Create Nature as " << num << std::endl; + } + ~Nature() { + std::cout << "Destroy Nature as " << num << std::endl; + } +}; +class SuperPrime { +private: + std::vector natures; +public: + SuperPrime(int a, int b) { + std::cout << "Create SuperPrime from " << a << " to " << b << std::endl; + for(int i = a; i < b; i++) { + Nature nat(i); + std::cout << "HAHA" << std::endl; + natures.push_back(nat); + std::cout << "DDDDD" << std::endl; + } + } + ~SuperPrime() { + std::cout << "Destroy SuperPrime " << std::endl; + } + + Nature max() { + std::vector::iterate it = natures.begin(); + Nature max(0); + for(; it != natures.end(); it ++) { + if(it->isSuperPrime()) { + if (max.compare(*it)) { + max = *it; + } + } + } + return max; + } +}; +int main() { + SuperPrime sp(10, 13); + Nature n = sp.max(); + std::cout << "锟斤拷蟪锟斤拷锟斤拷锟斤拷锟" ; + n.show(); + + return 0; +} From d0202fd9d8ee7c80e11649e93061ee9bae61d9a3 Mon Sep 17 00:00:00 2001 From: Dashark Date: Tue, 13 Apr 2021 20:30:25 +0800 Subject: [PATCH 20/89] compile new homework --- Makefile | 1 + 1 file changed, 1 insertion(+) diff --git a/Makefile b/Makefile index 49e28f73..32f9c531 100644 --- a/Makefile +++ b/Makefile @@ -5,6 +5,7 @@ main:main.cpp sp:SuperPrime_HW.cpp $(CXX) SuperPrime_HW.cpp -o sp + $(CXX) SuperPrime_HW2.cpp -o sp check: From 7ced164aa46042bc9dfc83cd2de765154595d4c3 Mon Sep 17 00:00:00 2001 From: Biuviu <1573560881@qq.com> Date: Wed, 14 Apr 2021 14:01:59 +0800 Subject: [PATCH 21/89] test --- hello.cpp | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 hello.cpp diff --git a/hello.cpp b/hello.cpp new file mode 100644 index 00000000..ad95e4ff --- /dev/null +++ b/hello.cpp @@ -0,0 +1,7 @@ +#include +#include +using namespace std; +int main(){ + cout<<"hello world"; + return 0; +} From f7680ecacf536e861370239b0cb8817c537f4c9b Mon Sep 17 00:00:00 2001 From: biuviu <1573560881@qq.com> Date: Thu, 15 Apr 2021 09:55:09 +0800 Subject: [PATCH 22/89] xx --- hello.cpp | 7 ------- 1 file changed, 7 deletions(-) delete mode 100644 hello.cpp diff --git a/hello.cpp b/hello.cpp deleted file mode 100644 index ad95e4ff..00000000 --- a/hello.cpp +++ /dev/null @@ -1,7 +0,0 @@ -#include -#include -using namespace std; -int main(){ - cout<<"hello world"; - return 0; -} From c83b3803ff7484a7b663f59c3179844155bb8c06 Mon Sep 17 00:00:00 2001 From: Biuviu <33221210+Biuviu@users.noreply.github.com> Date: Thu, 15 Apr 2021 10:03:05 +0800 Subject: [PATCH 23/89] Delete HelloWorld.cpp --- HelloWorld.cpp | 7 ------- 1 file changed, 7 deletions(-) delete mode 100644 HelloWorld.cpp diff --git a/HelloWorld.cpp b/HelloWorld.cpp deleted file mode 100644 index 3ef03e04..00000000 --- a/HelloWorld.cpp +++ /dev/null @@ -1,7 +0,0 @@ -#include "HelloWorld.h" -#include - -void HelloWorld::hello() { - std::cout << "Hello World!" << std::endl; -} - From 19886af2c038c5fd86fa5892c053d40f2a858f37 Mon Sep 17 00:00:00 2001 From: Biuviu <33221210+Biuviu@users.noreply.github.com> Date: Thu, 15 Apr 2021 10:04:13 +0800 Subject: [PATCH 24/89] Create HelloWorld.cpp --- HelloWorld.cpp | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 HelloWorld.cpp diff --git a/HelloWorld.cpp b/HelloWorld.cpp new file mode 100644 index 00000000..df2cef0d --- /dev/null +++ b/HelloWorld.cpp @@ -0,0 +1,7 @@ + +#include "HelloWorld.h" +#include + +void HelloWorld::hello() { + std::cout << "Hello World!" << std::endl; +} From fd6d1a0468c29bd3785da948930d56cf933568cd Mon Sep 17 00:00:00 2001 From: Biuviu <33221210+Biuviu@users.noreply.github.com> Date: Sat, 17 Apr 2021 14:28:46 +0800 Subject: [PATCH 25/89] Update SuperPrime-HW2.cpp --- SuperPrime-HW2.cpp | 53 ++-------------------------------------------- 1 file changed, 2 insertions(+), 51 deletions(-) diff --git a/SuperPrime-HW2.cpp b/SuperPrime-HW2.cpp index 9f16866e..7b5396e6 100644 --- a/SuperPrime-HW2.cpp +++ b/SuperPrime-HW2.cpp @@ -1,57 +1,8 @@ #include #include -class Nature { -private: - int num; -public: - Nature():num(0){ - std::cout << "Default Create Nature as " << num << std::endl; - } - Nature(int n):num(n) { - std::cout << "Create Nature as " << num << std::endl; - } - Nature(const Nature &nat):num(nat.num){ - std::cout << "Copy Create Nature as " << num << std::endl; - } - ~Nature() { - std::cout << "Destroy Nature as " << num << std::endl; - } -}; -class SuperPrime { -private: - std::vector natures; -public: - SuperPrime(int a, int b) { - std::cout << "Create SuperPrime from " << a << " to " << b << std::endl; - for(int i = a; i < b; i++) { - Nature nat(i); - std::cout << "HAHA" << std::endl; - natures.push_back(nat); - std::cout << "DDDDD" << std::endl; - } - } - ~SuperPrime() { - std::cout << "Destroy SuperPrime " << std::endl; - } - - Nature max() { - std::vector::iterate it = natures.begin(); - Nature max(0); - for(; it != natures.end(); it ++) { - if(it->isSuperPrime()) { - if (max.compare(*it)) { - max = *it; - } - } - } - return max; - } -}; + int main() { - SuperPrime sp(10, 13); - Nature n = sp.max(); - std::cout << "锟斤拷蟪锟斤拷锟斤拷锟斤拷锟" ; - n.show(); + return 0; } From 761d8537412326713ff2662a22f6eb14c6bad180 Mon Sep 17 00:00:00 2001 From: biuviu <1573560881@qq.com> Date: Sat, 17 Apr 2021 20:04:25 +0800 Subject: [PATCH 26/89] update --- HelloWorld.cpp | 2 +- SuperPrime-HW2.cpp | 53 ++++++++++++++++++++++++++++++++++++++++++++-- main.cpp | 2 -- 3 files changed, 52 insertions(+), 5 deletions(-) diff --git a/HelloWorld.cpp b/HelloWorld.cpp index df2cef0d..3ef03e04 100644 --- a/HelloWorld.cpp +++ b/HelloWorld.cpp @@ -1,7 +1,7 @@ - #include "HelloWorld.h" #include void HelloWorld::hello() { std::cout << "Hello World!" << std::endl; } + diff --git a/SuperPrime-HW2.cpp b/SuperPrime-HW2.cpp index 7b5396e6..9f16866e 100644 --- a/SuperPrime-HW2.cpp +++ b/SuperPrime-HW2.cpp @@ -1,8 +1,57 @@ #include #include - -int main() { +class Nature { +private: + int num; +public: + Nature():num(0){ + std::cout << "Default Create Nature as " << num << std::endl; + } + Nature(int n):num(n) { + std::cout << "Create Nature as " << num << std::endl; + } + Nature(const Nature &nat):num(nat.num){ + std::cout << "Copy Create Nature as " << num << std::endl; + } + ~Nature() { + std::cout << "Destroy Nature as " << num << std::endl; + } +}; +class SuperPrime { +private: + std::vector natures; +public: + SuperPrime(int a, int b) { + std::cout << "Create SuperPrime from " << a << " to " << b << std::endl; + for(int i = a; i < b; i++) { + Nature nat(i); + std::cout << "HAHA" << std::endl; + natures.push_back(nat); + std::cout << "DDDDD" << std::endl; + } + } + ~SuperPrime() { + std::cout << "Destroy SuperPrime " << std::endl; + } + Nature max() { + std::vector::iterate it = natures.begin(); + Nature max(0); + for(; it != natures.end(); it ++) { + if(it->isSuperPrime()) { + if (max.compare(*it)) { + max = *it; + } + } + } + return max; + } +}; +int main() { + SuperPrime sp(10, 13); + Nature n = sp.max(); + std::cout << "锟斤拷蟪锟斤拷锟斤拷锟斤拷锟" ; + n.show(); return 0; } diff --git a/main.cpp b/main.cpp index a611adbe..fec95e9b 100644 --- a/main.cpp +++ b/main.cpp @@ -7,8 +7,6 @@ class HelloWorld { }; int main() { HelloWorld hw; - HelloWorld w; hw.hello(); - w.hello(); return 0; } From e891fc6c0dac32d4aea64bed22c90aa4cca521e9 Mon Sep 17 00:00:00 2001 From: Biuviu <33221210+Biuviu@users.noreply.github.com> Date: Sat, 17 Apr 2021 20:18:12 +0800 Subject: [PATCH 27/89] Update SuperPrime-HW2.cpp --- SuperPrime-HW2.cpp | 53 +--------------------------------------------- 1 file changed, 1 insertion(+), 52 deletions(-) diff --git a/SuperPrime-HW2.cpp b/SuperPrime-HW2.cpp index 9f16866e..e48baec7 100644 --- a/SuperPrime-HW2.cpp +++ b/SuperPrime-HW2.cpp @@ -1,57 +1,6 @@ #include -#include -class Nature { -private: - int num; -public: - Nature():num(0){ - std::cout << "Default Create Nature as " << num << std::endl; - } - Nature(int n):num(n) { - std::cout << "Create Nature as " << num << std::endl; - } - Nature(const Nature &nat):num(nat.num){ - std::cout << "Copy Create Nature as " << num << std::endl; - } - ~Nature() { - std::cout << "Destroy Nature as " << num << std::endl; - } -}; -class SuperPrime { -private: - std::vector natures; -public: - SuperPrime(int a, int b) { - std::cout << "Create SuperPrime from " << a << " to " << b << std::endl; - for(int i = a; i < b; i++) { - Nature nat(i); - std::cout << "HAHA" << std::endl; - natures.push_back(nat); - std::cout << "DDDDD" << std::endl; - } - } - ~SuperPrime() { - std::cout << "Destroy SuperPrime " << std::endl; - } - - Nature max() { - std::vector::iterate it = natures.begin(); - Nature max(0); - for(; it != natures.end(); it ++) { - if(it->isSuperPrime()) { - if (max.compare(*it)) { - max = *it; - } - } - } - return max; - } -}; +using namespace std; int main() { - SuperPrime sp(10, 13); - Nature n = sp.max(); - std::cout << "锟斤拷蟪锟斤拷锟斤拷锟斤拷锟" ; - n.show(); return 0; } From 1ffcad9ad51aca26f9d81b52cb7c1071631be75d Mon Sep 17 00:00:00 2001 From: Biuviu <33221210+Biuviu@users.noreply.github.com> Date: Sat, 17 Apr 2021 20:20:02 +0800 Subject: [PATCH 28/89] Update SuperPrime-HW2.cpp --- SuperPrime-HW2.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/SuperPrime-HW2.cpp b/SuperPrime-HW2.cpp index e48baec7..e43e1377 100644 --- a/SuperPrime-HW2.cpp +++ b/SuperPrime-HW2.cpp @@ -1,5 +1,3 @@ -#include -using namespace std; int main() { return 0; From 52f147e8d20166cb2d90b74312f6b8a5031a1a64 Mon Sep 17 00:00:00 2001 From: biuviu <1573560881@qq.com> Date: Tue, 20 Apr 2021 10:16:55 +0800 Subject: [PATCH 29/89] update --- SuperPrime-HW2.cpp | 53 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/SuperPrime-HW2.cpp b/SuperPrime-HW2.cpp index e43e1377..9f16866e 100644 --- a/SuperPrime-HW2.cpp +++ b/SuperPrime-HW2.cpp @@ -1,4 +1,57 @@ +#include +#include +class Nature { +private: + int num; +public: + Nature():num(0){ + std::cout << "Default Create Nature as " << num << std::endl; + } + Nature(int n):num(n) { + std::cout << "Create Nature as " << num << std::endl; + } + Nature(const Nature &nat):num(nat.num){ + std::cout << "Copy Create Nature as " << num << std::endl; + } + ~Nature() { + std::cout << "Destroy Nature as " << num << std::endl; + } +}; +class SuperPrime { +private: + std::vector natures; +public: + SuperPrime(int a, int b) { + std::cout << "Create SuperPrime from " << a << " to " << b << std::endl; + for(int i = a; i < b; i++) { + Nature nat(i); + std::cout << "HAHA" << std::endl; + natures.push_back(nat); + std::cout << "DDDDD" << std::endl; + } + } + ~SuperPrime() { + std::cout << "Destroy SuperPrime " << std::endl; + } + + Nature max() { + std::vector::iterate it = natures.begin(); + Nature max(0); + for(; it != natures.end(); it ++) { + if(it->isSuperPrime()) { + if (max.compare(*it)) { + max = *it; + } + } + } + return max; + } +}; int main() { + SuperPrime sp(10, 13); + Nature n = sp.max(); + std::cout << "锟斤拷蟪锟斤拷锟斤拷锟斤拷锟" ; + n.show(); return 0; } From f154d6b3a9eeeb4afe19a43c578cdaa69d16702b Mon Sep 17 00:00:00 2001 From: Lake Hoo Date: Tue, 20 Apr 2021 18:35:10 +0800 Subject: [PATCH 30/89] =?UTF-8?q?=E7=BB=A7=E6=89=BF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SuperPrime-HW2.cpp => SuperPrime_HW2.cpp | 61 +++++++++++++++++++----- 1 file changed, 49 insertions(+), 12 deletions(-) rename SuperPrime-HW2.cpp => SuperPrime_HW2.cpp (50%) diff --git a/SuperPrime-HW2.cpp b/SuperPrime_HW2.cpp similarity index 50% rename from SuperPrime-HW2.cpp rename to SuperPrime_HW2.cpp index 9f16866e..ec1c77f3 100644 --- a/SuperPrime-HW2.cpp +++ b/SuperPrime_HW2.cpp @@ -16,33 +16,70 @@ class Nature { ~Nature() { std::cout << "Destroy Nature as " << num << std::endl; } + bool isPrime() { + if(num == 1 || num == 0) + return false; + for(int i = 2; i <= (int)sqrt(num); i++) + { + if(num % i == 0) + return false; + } + return true; + } + int compare(const Nature &nat) { + if (num > nat.num) + return 1; + else if(num == nat.num) + return 0; + + return -1; + } +private: +}; +class SuperPrime : public Nature { +private: + int num; +public: + SuperPrime(int n):num(n) { + } + bool isPrime() { + Nature nat(num); + return nat.isPrime(); + } + int compare(const SuperPrime &nat) { + if (num > nat.num) + return 1; + else if(num == nat.num) + return 0; + + return -1; + } }; -class SuperPrime { +class Container { private: - std::vector natures; + std::vector natures; public: - SuperPrime(int a, int b) { + Container(int a, int b) { std::cout << "Create SuperPrime from " << a << " to " << b << std::endl; for(int i = a; i < b; i++) { - Nature nat(i); + SuperPrime nat(i); std::cout << "HAHA" << std::endl; - natures.push_back(nat); + if(nat.isSuperPrime()) + natures.push_back(nat); std::cout << "DDDDD" << std::endl; } } - ~SuperPrime() { + ~Container() { std::cout << "Destroy SuperPrime " << std::endl; } - Nature max() { - std::vector::iterate it = natures.begin(); + SuperPrime max() { + std::vector::iterate it = natures.begin(); Nature max(0); for(; it != natures.end(); it ++) { - if(it->isSuperPrime()) { - if (max.compare(*it)) { + if (max.compare(*it)) { max = *it; - } - } + } } return max; } From 421cd256a90a9d90a7fb767cf34826bf971cbd44 Mon Sep 17 00:00:00 2001 From: Biuviu <33221210+Biuviu@users.noreply.github.com> Date: Tue, 20 Apr 2021 20:54:24 +0800 Subject: [PATCH 31/89] Update SuperPrime-HW2.cpp --- SuperPrime-HW2.cpp | 54 ++-------------------------------------------- 1 file changed, 2 insertions(+), 52 deletions(-) diff --git a/SuperPrime-HW2.cpp b/SuperPrime-HW2.cpp index 9f16866e..0d721f7a 100644 --- a/SuperPrime-HW2.cpp +++ b/SuperPrime-HW2.cpp @@ -1,57 +1,7 @@ #include -#include -class Nature { -private: - int num; -public: - Nature():num(0){ - std::cout << "Default Create Nature as " << num << std::endl; - } - Nature(int n):num(n) { - std::cout << "Create Nature as " << num << std::endl; - } - Nature(const Nature &nat):num(nat.num){ - std::cout << "Copy Create Nature as " << num << std::endl; - } - ~Nature() { - std::cout << "Destroy Nature as " << num << std::endl; - } -}; -class SuperPrime { -private: - std::vector natures; -public: - SuperPrime(int a, int b) { - std::cout << "Create SuperPrime from " << a << " to " << b << std::endl; - for(int i = a; i < b; i++) { - Nature nat(i); - std::cout << "HAHA" << std::endl; - natures.push_back(nat); - std::cout << "DDDDD" << std::endl; - } - } - ~SuperPrime() { - std::cout << "Destroy SuperPrime " << std::endl; - } - - Nature max() { - std::vector::iterate it = natures.begin(); - Nature max(0); - for(; it != natures.end(); it ++) { - if(it->isSuperPrime()) { - if (max.compare(*it)) { - max = *it; - } - } - } - return max; - } -}; +useing namespace std; int main() { - SuperPrime sp(10, 13); - Nature n = sp.max(); - std::cout << "锟斤拷蟪锟斤拷锟斤拷锟斤拷锟" ; - n.show(); + return 0; } From f9113c78ae805e2f369c627734bda3c23992a44b Mon Sep 17 00:00:00 2001 From: Biuviu <33221210+Biuviu@users.noreply.github.com> Date: Tue, 20 Apr 2021 20:56:49 +0800 Subject: [PATCH 32/89] Update SuperPrime-HW2.cpp --- SuperPrime-HW2.cpp | 116 ++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 109 insertions(+), 7 deletions(-) diff --git a/SuperPrime-HW2.cpp b/SuperPrime-HW2.cpp index 0d721f7a..3da0554a 100644 --- a/SuperPrime-HW2.cpp +++ b/SuperPrime-HW2.cpp @@ -1,7 +1,109 @@ -#include -useing namespace std; -int main() { - - - return 0; -} +#include +#include + +using namespace std; + +class SuperPrime { +private: + bool nature_range[1000];//绱犳暟鏁扮粍瀛樻斁 + bool super_range[1000];//瓒呯骇绱犳暟瀛樻斁 + int left;//宸﹁竟鐣 + int right;//鍙宠竟鐣 + int count;//鏁扮洰 +public: + SuperPrime(int a, int b) :left(a), right(b) { + count = 0; + for (int i = 0; i < 1000; i++) + { + nature_range[i] = false; + } + //鍒濆鍖 + for (int i = 0; i < 1000; i++) + { + super_range[i] = false; + } + //鍒濆鍖 + for (int i = 0; i < 1000;i++) + { + int flag = 0; + for (int j = 2; j < i; j++) + { + if (i % j == 0) + { + flag = 1; + break; + } + } + if (flag == 0) + nature_range[i] = true; + } + //鍒ゆ柇绱犳暟(0~1000) + for (int i = a; i <= b; i++) + { + if (nature_range[i] == true&&i>100) + { + int hun, dec, uni; + uni = i % 10, dec = (i / 10) % 10, hun = i / 100; + int sum = uni + dec + hun;//鍜 + int pro = uni * dec * hun;//绉 + int sum_qua = uni * uni + dec * dec + hun * hun;//骞虫柟鍜 + if (nature_range[sum] == true && nature_range[pro] == true && nature_range[sum_qua] == true) + { + super_range[i] = true; + count++; + } + } + } + //鍒ゆ柇瓒呯骇绱犳暟(a~b) + } + //鏋勯犲嚱鏁 + ~SuperPrime(){} + //鏋愭瀯鍑芥暟 + int max(); + int recount(); + int sum_super(); + void print(); +}; +int SuperPrime::max() { + for (int i = SuperPrime::right; i > SuperPrime::left; i--) + { + if (super_range[i] == true) + { + return i; + } + } +} +int SuperPrime::recount() { + return SuperPrime::count; +} +int SuperPrime::sum_super() { + int sum = 0; + for (int i = left; i <= right; i++) + { + if (super_range[i] == true) + { + sum += i; + } + } + return sum; +} +void SuperPrime::print(){ + for (int i = left; i <= right; i++) + { + if (super_range[i] == true) + { + cout << i << " "; + } + } +} +int main() +{ + SuperPrime sup(100, 999); + cout << "瓒呯骇绱犳暟锛"; + sup.print(); + cout << endl; + cout << "鏈澶у:" << sup.max() << endl; + cout << "鏁扮洰锛" << sup.recount() << endl; + cout << "鎬诲拰锛" << sup.sum_super() << endl; + return 0; +} From fa300d27d9ad2b6584ca2e8565f2008ee6eda70e Mon Sep 17 00:00:00 2001 From: Biuviu <33221210+Biuviu@users.noreply.github.com> Date: Tue, 20 Apr 2021 21:22:07 +0800 Subject: [PATCH 33/89] Update SuperPrime-HW2.cpp --- SuperPrime-HW2.cpp | 101 +-------------------------------------------- 1 file changed, 1 insertion(+), 100 deletions(-) diff --git a/SuperPrime-HW2.cpp b/SuperPrime-HW2.cpp index 3da0554a..accbfcda 100644 --- a/SuperPrime-HW2.cpp +++ b/SuperPrime-HW2.cpp @@ -3,107 +3,8 @@ using namespace std; -class SuperPrime { -private: - bool nature_range[1000];//绱犳暟鏁扮粍瀛樻斁 - bool super_range[1000];//瓒呯骇绱犳暟瀛樻斁 - int left;//宸﹁竟鐣 - int right;//鍙宠竟鐣 - int count;//鏁扮洰 -public: - SuperPrime(int a, int b) :left(a), right(b) { - count = 0; - for (int i = 0; i < 1000; i++) - { - nature_range[i] = false; - } - //鍒濆鍖 - for (int i = 0; i < 1000; i++) - { - super_range[i] = false; - } - //鍒濆鍖 - for (int i = 0; i < 1000;i++) - { - int flag = 0; - for (int j = 2; j < i; j++) - { - if (i % j == 0) - { - flag = 1; - break; - } - } - if (flag == 0) - nature_range[i] = true; - } - //鍒ゆ柇绱犳暟(0~1000) - for (int i = a; i <= b; i++) - { - if (nature_range[i] == true&&i>100) - { - int hun, dec, uni; - uni = i % 10, dec = (i / 10) % 10, hun = i / 100; - int sum = uni + dec + hun;//鍜 - int pro = uni * dec * hun;//绉 - int sum_qua = uni * uni + dec * dec + hun * hun;//骞虫柟鍜 - if (nature_range[sum] == true && nature_range[pro] == true && nature_range[sum_qua] == true) - { - super_range[i] = true; - count++; - } - } - } - //鍒ゆ柇瓒呯骇绱犳暟(a~b) - } - //鏋勯犲嚱鏁 - ~SuperPrime(){} - //鏋愭瀯鍑芥暟 - int max(); - int recount(); - int sum_super(); - void print(); -}; -int SuperPrime::max() { - for (int i = SuperPrime::right; i > SuperPrime::left; i--) - { - if (super_range[i] == true) - { - return i; - } - } -} -int SuperPrime::recount() { - return SuperPrime::count; -} -int SuperPrime::sum_super() { - int sum = 0; - for (int i = left; i <= right; i++) - { - if (super_range[i] == true) - { - sum += i; - } - } - return sum; -} -void SuperPrime::print(){ - for (int i = left; i <= right; i++) - { - if (super_range[i] == true) - { - cout << i << " "; - } - } -} int main() { - SuperPrime sup(100, 999); - cout << "瓒呯骇绱犳暟锛"; - sup.print(); - cout << endl; - cout << "鏈澶у:" << sup.max() << endl; - cout << "鏁扮洰锛" << sup.recount() << endl; - cout << "鎬诲拰锛" << sup.sum_super() << endl; + return 0; } From b25caa9a1a93dc1042f11590663370e227ce8ec7 Mon Sep 17 00:00:00 2001 From: biuviu <1573560881@qq.com> Date: Tue, 20 Apr 2021 21:28:05 +0800 Subject: [PATCH 34/89] hh --- SuperPrime-HW2.cpp | 10 ----- SuperPrime_HW2.cpp | 94 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 94 insertions(+), 10 deletions(-) delete mode 100644 SuperPrime-HW2.cpp create mode 100644 SuperPrime_HW2.cpp diff --git a/SuperPrime-HW2.cpp b/SuperPrime-HW2.cpp deleted file mode 100644 index accbfcda..00000000 --- a/SuperPrime-HW2.cpp +++ /dev/null @@ -1,10 +0,0 @@ -#include -#include - -using namespace std; - -int main() -{ - - return 0; -} diff --git a/SuperPrime_HW2.cpp b/SuperPrime_HW2.cpp new file mode 100644 index 00000000..ec1c77f3 --- /dev/null +++ b/SuperPrime_HW2.cpp @@ -0,0 +1,94 @@ +#include +#include +class Nature { +private: + int num; +public: + Nature():num(0){ + std::cout << "Default Create Nature as " << num << std::endl; + } + Nature(int n):num(n) { + std::cout << "Create Nature as " << num << std::endl; + } + Nature(const Nature &nat):num(nat.num){ + std::cout << "Copy Create Nature as " << num << std::endl; + } + ~Nature() { + std::cout << "Destroy Nature as " << num << std::endl; + } + bool isPrime() { + if(num == 1 || num == 0) + return false; + for(int i = 2; i <= (int)sqrt(num); i++) + { + if(num % i == 0) + return false; + } + return true; + } + int compare(const Nature &nat) { + if (num > nat.num) + return 1; + else if(num == nat.num) + return 0; + + return -1; + } +private: +}; +class SuperPrime : public Nature { +private: + int num; +public: + SuperPrime(int n):num(n) { + } + bool isPrime() { + Nature nat(num); + return nat.isPrime(); + } + int compare(const SuperPrime &nat) { + if (num > nat.num) + return 1; + else if(num == nat.num) + return 0; + + return -1; + } +}; +class Container { +private: + std::vector natures; +public: + Container(int a, int b) { + std::cout << "Create SuperPrime from " << a << " to " << b << std::endl; + for(int i = a; i < b; i++) { + SuperPrime nat(i); + std::cout << "HAHA" << std::endl; + if(nat.isSuperPrime()) + natures.push_back(nat); + std::cout << "DDDDD" << std::endl; + } + } + ~Container() { + std::cout << "Destroy SuperPrime " << std::endl; + } + + SuperPrime max() { + std::vector::iterate it = natures.begin(); + Nature max(0); + for(; it != natures.end(); it ++) { + if (max.compare(*it)) { + max = *it; + } + } + return max; + } +}; +int main() { + SuperPrime sp(10, 13); + Nature n = sp.max(); + std::cout << "锟斤拷蟪锟斤拷锟斤拷锟斤拷锟" ; + n.show(); + + return 0; +} From 967da80d31c017b531b6d16a179c5385f3029f06 Mon Sep 17 00:00:00 2001 From: Biuviu <33221210+Biuviu@users.noreply.github.com> Date: Tue, 20 Apr 2021 21:31:58 +0800 Subject: [PATCH 35/89] Update SuperPrime_HW2.cpp --- SuperPrime_HW2.cpp | 24 +----------------------- 1 file changed, 1 insertion(+), 23 deletions(-) diff --git a/SuperPrime_HW2.cpp b/SuperPrime_HW2.cpp index ec1c77f3..cef4fbe0 100644 --- a/SuperPrime_HW2.cpp +++ b/SuperPrime_HW2.cpp @@ -3,29 +3,7 @@ class Nature { private: int num; -public: - Nature():num(0){ - std::cout << "Default Create Nature as " << num << std::endl; - } - Nature(int n):num(n) { - std::cout << "Create Nature as " << num << std::endl; - } - Nature(const Nature &nat):num(nat.num){ - std::cout << "Copy Create Nature as " << num << std::endl; - } - ~Nature() { - std::cout << "Destroy Nature as " << num << std::endl; - } - bool isPrime() { - if(num == 1 || num == 0) - return false; - for(int i = 2; i <= (int)sqrt(num); i++) - { - if(num % i == 0) - return false; - } - return true; - } + int compare(const Nature &nat) { if (num > nat.num) return 1; From 62aec7e82088ed7849da6a691d28790a1d806d2a Mon Sep 17 00:00:00 2001 From: Biuviu <33221210+Biuviu@users.noreply.github.com> Date: Tue, 20 Apr 2021 21:33:01 +0800 Subject: [PATCH 36/89] Update SuperPrime_HW2.cpp --- SuperPrime_HW2.cpp | 65 ---------------------------------------------- 1 file changed, 65 deletions(-) diff --git a/SuperPrime_HW2.cpp b/SuperPrime_HW2.cpp index cef4fbe0..58edba93 100644 --- a/SuperPrime_HW2.cpp +++ b/SuperPrime_HW2.cpp @@ -1,72 +1,7 @@ #include #include -class Nature { -private: - int num; - int compare(const Nature &nat) { - if (num > nat.num) - return 1; - else if(num == nat.num) - return 0; - - return -1; - } -private: -}; -class SuperPrime : public Nature { -private: - int num; -public: - SuperPrime(int n):num(n) { - } - bool isPrime() { - Nature nat(num); - return nat.isPrime(); - } - int compare(const SuperPrime &nat) { - if (num > nat.num) - return 1; - else if(num == nat.num) - return 0; - - return -1; - } -}; -class Container { -private: - std::vector natures; -public: - Container(int a, int b) { - std::cout << "Create SuperPrime from " << a << " to " << b << std::endl; - for(int i = a; i < b; i++) { - SuperPrime nat(i); - std::cout << "HAHA" << std::endl; - if(nat.isSuperPrime()) - natures.push_back(nat); - std::cout << "DDDDD" << std::endl; - } - } - ~Container() { - std::cout << "Destroy SuperPrime " << std::endl; - } - - SuperPrime max() { - std::vector::iterate it = natures.begin(); - Nature max(0); - for(; it != natures.end(); it ++) { - if (max.compare(*it)) { - max = *it; - } - } - return max; - } -}; int main() { - SuperPrime sp(10, 13); - Nature n = sp.max(); - std::cout << "锟斤拷蟪锟斤拷锟斤拷锟斤拷锟" ; - n.show(); return 0; } From c74be462ad72c84548c2f2aa48f0dbb75940fc34 Mon Sep 17 00:00:00 2001 From: biuviu <1573560881@qq.com> Date: Fri, 23 Apr 2021 13:25:06 +0800 Subject: [PATCH 37/89] update --- SuperPrime_HW2.cpp | 89 +++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 88 insertions(+), 1 deletion(-) diff --git a/SuperPrime_HW2.cpp b/SuperPrime_HW2.cpp index 58edba93..c04e0faf 100644 --- a/SuperPrime_HW2.cpp +++ b/SuperPrime_HW2.cpp @@ -1,7 +1,94 @@ #include #include - +class Nature { +private: + int num; +public: + Nature():num(0){ + std::cout << "Default Create Nature as " << num << std::endl; + } + Nature(int n):num(n) { + std::cout << "Create Nature as " << num << std::endl; + } + Nature(const Nature &nat):num(nat.num){ + std::cout << "Copy Create Nature as " << num << std::endl; + } + ~Nature() { + std::cout << "Destroy Nature as " << num << std::endl; + } + bool isPrime() { + if(num == 1 || num == 0) + return false; + for(int i = 2; i <= (int)sqrt(num); i++) + { + if(num % i == 0) + return false; + } + return true; + } + int compare(const Nature &nat) { + if (num > nat.num) + return 1; + else if(num == nat.num) + return 0; + + return -1; + } +private: +}; +class SuperPrime : public Nature { +private: + int num; +public: + SuperPrime(int n):num(n) { + } + bool isPrime() { + Nature nat(num); + return nat.isPrime(); + } + int compare(const SuperPrime &nat) { + if (num > nat.num) + return 1; + else if(num == nat.num) + return 0; + + return -1; + } +}; +class Container { +private: + std::vector natures; +public: + Container(int a, int b) { + std::cout << "Create SuperPrime from " << a << " to " << b << std::endl; + for(int i = a; i < b; i++) { + SuperPrime nat(i); + std::cout << "HAHA" << std::endl; + if(nat.isSuperPrime()) + natures.push_back(nat); + std::cout << "DDDDD" << std::endl; + } + } + ~Container() { + std::cout << "Destroy SuperPrime " << std::endl; + } + + SuperPrime max() { + std::vector::iterate it = natures.begin(); + Nature max(0); + for(; it != natures.end(); it ++) { + if (max.compare(*it)) { + max = *it; + } + } + return max; + } +}; int main() { + SuperPrime sp(10, 13); + Nature n = sp.max(); + std::cout << "???????????" ; + n.show(); return 0; } From d27e04f24b820bba505f94762d64bae16c3b8290 Mon Sep 17 00:00:00 2001 From: Biuviu <33221210+Biuviu@users.noreply.github.com> Date: Fri, 23 Apr 2021 13:32:11 +0800 Subject: [PATCH 38/89] Update SuperPrime_HW2.cpp --- SuperPrime_HW2.cpp | 90 ++-------------------------------------------- 1 file changed, 2 insertions(+), 88 deletions(-) diff --git a/SuperPrime_HW2.cpp b/SuperPrime_HW2.cpp index c04e0faf..6c5d9083 100644 --- a/SuperPrime_HW2.cpp +++ b/SuperPrime_HW2.cpp @@ -1,94 +1,8 @@ #include #include -class Nature { -private: - int num; -public: - Nature():num(0){ - std::cout << "Default Create Nature as " << num << std::endl; - } - Nature(int n):num(n) { - std::cout << "Create Nature as " << num << std::endl; - } - Nature(const Nature &nat):num(nat.num){ - std::cout << "Copy Create Nature as " << num << std::endl; - } - ~Nature() { - std::cout << "Destroy Nature as " << num << std::endl; - } - bool isPrime() { - if(num == 1 || num == 0) - return false; - for(int i = 2; i <= (int)sqrt(num); i++) - { - if(num % i == 0) - return false; - } - return true; - } - int compare(const Nature &nat) { - if (num > nat.num) - return 1; - else if(num == nat.num) - return 0; - - return -1; - } -private: -}; -class SuperPrime : public Nature { -private: - int num; -public: - SuperPrime(int n):num(n) { - } - bool isPrime() { - Nature nat(num); - return nat.isPrime(); - } - int compare(const SuperPrime &nat) { - if (num > nat.num) - return 1; - else if(num == nat.num) - return 0; - - return -1; - } -}; -class Container { -private: - std::vector natures; -public: - Container(int a, int b) { - std::cout << "Create SuperPrime from " << a << " to " << b << std::endl; - for(int i = a; i < b; i++) { - SuperPrime nat(i); - std::cout << "HAHA" << std::endl; - if(nat.isSuperPrime()) - natures.push_back(nat); - std::cout << "DDDDD" << std::endl; - } - } - ~Container() { - std::cout << "Destroy SuperPrime " << std::endl; - } - - SuperPrime max() { - std::vector::iterate it = natures.begin(); - Nature max(0); - for(; it != natures.end(); it ++) { - if (max.compare(*it)) { - max = *it; - } - } - return max; - } -}; + int main() { - SuperPrime sp(10, 13); - Nature n = sp.max(); - std::cout << "???????????" ; - n.show(); + return 0; } From ddae1701acad65a7d617344b843a66a4dd20be0d Mon Sep 17 00:00:00 2001 From: biuviu <1573560881@qq.com> Date: Fri, 23 Apr 2021 13:44:47 +0800 Subject: [PATCH 39/89] hll --- SuperPrime_HW2.cpp | 90 ++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 88 insertions(+), 2 deletions(-) diff --git a/SuperPrime_HW2.cpp b/SuperPrime_HW2.cpp index 6c5d9083..ec1c77f3 100644 --- a/SuperPrime_HW2.cpp +++ b/SuperPrime_HW2.cpp @@ -1,8 +1,94 @@ #include #include - +class Nature { +private: + int num; +public: + Nature():num(0){ + std::cout << "Default Create Nature as " << num << std::endl; + } + Nature(int n):num(n) { + std::cout << "Create Nature as " << num << std::endl; + } + Nature(const Nature &nat):num(nat.num){ + std::cout << "Copy Create Nature as " << num << std::endl; + } + ~Nature() { + std::cout << "Destroy Nature as " << num << std::endl; + } + bool isPrime() { + if(num == 1 || num == 0) + return false; + for(int i = 2; i <= (int)sqrt(num); i++) + { + if(num % i == 0) + return false; + } + return true; + } + int compare(const Nature &nat) { + if (num > nat.num) + return 1; + else if(num == nat.num) + return 0; + + return -1; + } +private: +}; +class SuperPrime : public Nature { +private: + int num; +public: + SuperPrime(int n):num(n) { + } + bool isPrime() { + Nature nat(num); + return nat.isPrime(); + } + int compare(const SuperPrime &nat) { + if (num > nat.num) + return 1; + else if(num == nat.num) + return 0; + + return -1; + } +}; +class Container { +private: + std::vector natures; +public: + Container(int a, int b) { + std::cout << "Create SuperPrime from " << a << " to " << b << std::endl; + for(int i = a; i < b; i++) { + SuperPrime nat(i); + std::cout << "HAHA" << std::endl; + if(nat.isSuperPrime()) + natures.push_back(nat); + std::cout << "DDDDD" << std::endl; + } + } + ~Container() { + std::cout << "Destroy SuperPrime " << std::endl; + } + + SuperPrime max() { + std::vector::iterate it = natures.begin(); + Nature max(0); + for(; it != natures.end(); it ++) { + if (max.compare(*it)) { + max = *it; + } + } + return max; + } +}; int main() { - + SuperPrime sp(10, 13); + Nature n = sp.max(); + std::cout << "锟斤拷蟪锟斤拷锟斤拷锟斤拷锟" ; + n.show(); return 0; } From c728e6ce656d52f7aa9af2e0166090646f43415c Mon Sep 17 00:00:00 2001 From: Biuviu <33221210+Biuviu@users.noreply.github.com> Date: Fri, 23 Apr 2021 13:46:59 +0800 Subject: [PATCH 40/89] Update SuperPrime_HW2.cpp --- SuperPrime_HW2.cpp | 90 ++-------------------------------------------- 1 file changed, 2 insertions(+), 88 deletions(-) diff --git a/SuperPrime_HW2.cpp b/SuperPrime_HW2.cpp index ec1c77f3..6c5d9083 100644 --- a/SuperPrime_HW2.cpp +++ b/SuperPrime_HW2.cpp @@ -1,94 +1,8 @@ #include #include -class Nature { -private: - int num; -public: - Nature():num(0){ - std::cout << "Default Create Nature as " << num << std::endl; - } - Nature(int n):num(n) { - std::cout << "Create Nature as " << num << std::endl; - } - Nature(const Nature &nat):num(nat.num){ - std::cout << "Copy Create Nature as " << num << std::endl; - } - ~Nature() { - std::cout << "Destroy Nature as " << num << std::endl; - } - bool isPrime() { - if(num == 1 || num == 0) - return false; - for(int i = 2; i <= (int)sqrt(num); i++) - { - if(num % i == 0) - return false; - } - return true; - } - int compare(const Nature &nat) { - if (num > nat.num) - return 1; - else if(num == nat.num) - return 0; - - return -1; - } -private: -}; -class SuperPrime : public Nature { -private: - int num; -public: - SuperPrime(int n):num(n) { - } - bool isPrime() { - Nature nat(num); - return nat.isPrime(); - } - int compare(const SuperPrime &nat) { - if (num > nat.num) - return 1; - else if(num == nat.num) - return 0; - - return -1; - } -}; -class Container { -private: - std::vector natures; -public: - Container(int a, int b) { - std::cout << "Create SuperPrime from " << a << " to " << b << std::endl; - for(int i = a; i < b; i++) { - SuperPrime nat(i); - std::cout << "HAHA" << std::endl; - if(nat.isSuperPrime()) - natures.push_back(nat); - std::cout << "DDDDD" << std::endl; - } - } - ~Container() { - std::cout << "Destroy SuperPrime " << std::endl; - } - - SuperPrime max() { - std::vector::iterate it = natures.begin(); - Nature max(0); - for(; it != natures.end(); it ++) { - if (max.compare(*it)) { - max = *it; - } - } - return max; - } -}; + int main() { - SuperPrime sp(10, 13); - Nature n = sp.max(); - std::cout << "锟斤拷蟪锟斤拷锟斤拷锟斤拷锟" ; - n.show(); + return 0; } From 2c790e50e0046283158b73b7b45751a47e689d95 Mon Sep 17 00:00:00 2001 From: biuviu <1573560881@qq.com> Date: Sun, 25 Apr 2021 10:56:14 +0800 Subject: [PATCH 41/89] hw12 --- SuperPrime_HW2.cpp | 90 ++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 88 insertions(+), 2 deletions(-) diff --git a/SuperPrime_HW2.cpp b/SuperPrime_HW2.cpp index 6c5d9083..ec1c77f3 100644 --- a/SuperPrime_HW2.cpp +++ b/SuperPrime_HW2.cpp @@ -1,8 +1,94 @@ #include #include - +class Nature { +private: + int num; +public: + Nature():num(0){ + std::cout << "Default Create Nature as " << num << std::endl; + } + Nature(int n):num(n) { + std::cout << "Create Nature as " << num << std::endl; + } + Nature(const Nature &nat):num(nat.num){ + std::cout << "Copy Create Nature as " << num << std::endl; + } + ~Nature() { + std::cout << "Destroy Nature as " << num << std::endl; + } + bool isPrime() { + if(num == 1 || num == 0) + return false; + for(int i = 2; i <= (int)sqrt(num); i++) + { + if(num % i == 0) + return false; + } + return true; + } + int compare(const Nature &nat) { + if (num > nat.num) + return 1; + else if(num == nat.num) + return 0; + + return -1; + } +private: +}; +class SuperPrime : public Nature { +private: + int num; +public: + SuperPrime(int n):num(n) { + } + bool isPrime() { + Nature nat(num); + return nat.isPrime(); + } + int compare(const SuperPrime &nat) { + if (num > nat.num) + return 1; + else if(num == nat.num) + return 0; + + return -1; + } +}; +class Container { +private: + std::vector natures; +public: + Container(int a, int b) { + std::cout << "Create SuperPrime from " << a << " to " << b << std::endl; + for(int i = a; i < b; i++) { + SuperPrime nat(i); + std::cout << "HAHA" << std::endl; + if(nat.isSuperPrime()) + natures.push_back(nat); + std::cout << "DDDDD" << std::endl; + } + } + ~Container() { + std::cout << "Destroy SuperPrime " << std::endl; + } + + SuperPrime max() { + std::vector::iterate it = natures.begin(); + Nature max(0); + for(; it != natures.end(); it ++) { + if (max.compare(*it)) { + max = *it; + } + } + return max; + } +}; int main() { - + SuperPrime sp(10, 13); + Nature n = sp.max(); + std::cout << "锟斤拷蟪锟斤拷锟斤拷锟斤拷锟" ; + n.show(); return 0; } From 3e4e21a01040a5a62172fea75e72c7b492415c15 Mon Sep 17 00:00:00 2001 From: biuviu <1573560881@qq.com> Date: Sun, 25 Apr 2021 11:00:30 +0800 Subject: [PATCH 42/89] hw12 --- SuperPrime_HW.cpp | 4 ++- SuperPrime_HW2.cpp | 90 ++-------------------------------------------- 2 files changed, 5 insertions(+), 89 deletions(-) diff --git a/SuperPrime_HW.cpp b/SuperPrime_HW.cpp index 0e004b50..b6374190 100644 --- a/SuperPrime_HW.cpp +++ b/SuperPrime_HW.cpp @@ -1,5 +1,7 @@ #include - +using namespace std; int main() { + cout<<"hello"< #include -class Nature { -private: - int num; -public: - Nature():num(0){ - std::cout << "Default Create Nature as " << num << std::endl; - } - Nature(int n):num(n) { - std::cout << "Create Nature as " << num << std::endl; - } - Nature(const Nature &nat):num(nat.num){ - std::cout << "Copy Create Nature as " << num << std::endl; - } - ~Nature() { - std::cout << "Destroy Nature as " << num << std::endl; - } - bool isPrime() { - if(num == 1 || num == 0) - return false; - for(int i = 2; i <= (int)sqrt(num); i++) - { - if(num % i == 0) - return false; - } - return true; - } - int compare(const Nature &nat) { - if (num > nat.num) - return 1; - else if(num == nat.num) - return 0; - - return -1; - } -private: -}; -class SuperPrime : public Nature { -private: - int num; -public: - SuperPrime(int n):num(n) { - } - bool isPrime() { - Nature nat(num); - return nat.isPrime(); - } - int compare(const SuperPrime &nat) { - if (num > nat.num) - return 1; - else if(num == nat.num) - return 0; - - return -1; - } -}; -class Container { -private: - std::vector natures; -public: - Container(int a, int b) { - std::cout << "Create SuperPrime from " << a << " to " << b << std::endl; - for(int i = a; i < b; i++) { - SuperPrime nat(i); - std::cout << "HAHA" << std::endl; - if(nat.isSuperPrime()) - natures.push_back(nat); - std::cout << "DDDDD" << std::endl; - } - } - ~Container() { - std::cout << "Destroy SuperPrime " << std::endl; - } - - SuperPrime max() { - std::vector::iterate it = natures.begin(); - Nature max(0); - for(; it != natures.end(); it ++) { - if (max.compare(*it)) { - max = *it; - } - } - return max; - } -}; + int main() { - SuperPrime sp(10, 13); - Nature n = sp.max(); - std::cout << "锟斤拷蟪锟斤拷锟斤拷锟斤拷锟" ; - n.show(); + return 0; } From 799bf2f2c90385200a4556d2eff496ea4c6ddaae Mon Sep 17 00:00:00 2001 From: biuviu <1573560881@qq.com> Date: Sun, 25 Apr 2021 11:03:36 +0800 Subject: [PATCH 43/89] hw12 --- SuperPrime_HW2.cpp | 90 ++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 88 insertions(+), 2 deletions(-) diff --git a/SuperPrime_HW2.cpp b/SuperPrime_HW2.cpp index 7b5396e6..ec1c77f3 100644 --- a/SuperPrime_HW2.cpp +++ b/SuperPrime_HW2.cpp @@ -1,8 +1,94 @@ #include #include - -int main() { +class Nature { +private: + int num; +public: + Nature():num(0){ + std::cout << "Default Create Nature as " << num << std::endl; + } + Nature(int n):num(n) { + std::cout << "Create Nature as " << num << std::endl; + } + Nature(const Nature &nat):num(nat.num){ + std::cout << "Copy Create Nature as " << num << std::endl; + } + ~Nature() { + std::cout << "Destroy Nature as " << num << std::endl; + } + bool isPrime() { + if(num == 1 || num == 0) + return false; + for(int i = 2; i <= (int)sqrt(num); i++) + { + if(num % i == 0) + return false; + } + return true; + } + int compare(const Nature &nat) { + if (num > nat.num) + return 1; + else if(num == nat.num) + return 0; + + return -1; + } +private: +}; +class SuperPrime : public Nature { +private: + int num; +public: + SuperPrime(int n):num(n) { + } + bool isPrime() { + Nature nat(num); + return nat.isPrime(); + } + int compare(const SuperPrime &nat) { + if (num > nat.num) + return 1; + else if(num == nat.num) + return 0; + + return -1; + } +}; +class Container { +private: + std::vector natures; +public: + Container(int a, int b) { + std::cout << "Create SuperPrime from " << a << " to " << b << std::endl; + for(int i = a; i < b; i++) { + SuperPrime nat(i); + std::cout << "HAHA" << std::endl; + if(nat.isSuperPrime()) + natures.push_back(nat); + std::cout << "DDDDD" << std::endl; + } + } + ~Container() { + std::cout << "Destroy SuperPrime " << std::endl; + } + SuperPrime max() { + std::vector::iterate it = natures.begin(); + Nature max(0); + for(; it != natures.end(); it ++) { + if (max.compare(*it)) { + max = *it; + } + } + return max; + } +}; +int main() { + SuperPrime sp(10, 13); + Nature n = sp.max(); + std::cout << "锟斤拷蟪锟斤拷锟斤拷锟斤拷锟" ; + n.show(); return 0; } From 2da15b4b0a89ad224be26a4ef2d6c8bc502f5129 Mon Sep 17 00:00:00 2001 From: biuviu <1573560881@qq.com> Date: Sun, 25 Apr 2021 11:09:57 +0800 Subject: [PATCH 44/89] hw12 --- SuperPrime_HW2.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/SuperPrime_HW2.cpp b/SuperPrime_HW2.cpp index ec1c77f3..320ed6e0 100644 --- a/SuperPrime_HW2.cpp +++ b/SuperPrime_HW2.cpp @@ -89,6 +89,7 @@ int main() { Nature n = sp.max(); std::cout << "锟斤拷蟪锟斤拷锟斤拷锟斤拷锟" ; n.show(); + n.show(); return 0; } From 77782064bb0634b6f2a46904cc5597086ca7a25c Mon Sep 17 00:00:00 2001 From: biuviu <1573560881@qq.com> Date: Sun, 25 Apr 2021 11:17:27 +0800 Subject: [PATCH 45/89] hw12 --- SuperPrime_HW2.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/SuperPrime_HW2.cpp b/SuperPrime_HW2.cpp index 320ed6e0..5b8abba6 100644 --- a/SuperPrime_HW2.cpp +++ b/SuperPrime_HW2.cpp @@ -88,8 +88,7 @@ int main() { SuperPrime sp(10, 13); Nature n = sp.max(); std::cout << "锟斤拷蟪锟斤拷锟斤拷锟斤拷锟" ; - n.show(); - n.show(); + //n.show(); return 0; } From 6ecc3b280a02e0e0ccf3f274a1c4d3243d17300e Mon Sep 17 00:00:00 2001 From: biuviu <1573560881@qq.com> Date: Sun, 25 Apr 2021 14:16:18 +0800 Subject: [PATCH 46/89] hw12 --- SuperPrime_HW2.cpp | 90 ++-------------------------------------------- 1 file changed, 2 insertions(+), 88 deletions(-) diff --git a/SuperPrime_HW2.cpp b/SuperPrime_HW2.cpp index 5b8abba6..7b5396e6 100644 --- a/SuperPrime_HW2.cpp +++ b/SuperPrime_HW2.cpp @@ -1,94 +1,8 @@ #include #include -class Nature { -private: - int num; -public: - Nature():num(0){ - std::cout << "Default Create Nature as " << num << std::endl; - } - Nature(int n):num(n) { - std::cout << "Create Nature as " << num << std::endl; - } - Nature(const Nature &nat):num(nat.num){ - std::cout << "Copy Create Nature as " << num << std::endl; - } - ~Nature() { - std::cout << "Destroy Nature as " << num << std::endl; - } - bool isPrime() { - if(num == 1 || num == 0) - return false; - for(int i = 2; i <= (int)sqrt(num); i++) - { - if(num % i == 0) - return false; - } - return true; - } - int compare(const Nature &nat) { - if (num > nat.num) - return 1; - else if(num == nat.num) - return 0; - - return -1; - } -private: -}; -class SuperPrime : public Nature { -private: - int num; -public: - SuperPrime(int n):num(n) { - } - bool isPrime() { - Nature nat(num); - return nat.isPrime(); - } - int compare(const SuperPrime &nat) { - if (num > nat.num) - return 1; - else if(num == nat.num) - return 0; - - return -1; - } -}; -class Container { -private: - std::vector natures; -public: - Container(int a, int b) { - std::cout << "Create SuperPrime from " << a << " to " << b << std::endl; - for(int i = a; i < b; i++) { - SuperPrime nat(i); - std::cout << "HAHA" << std::endl; - if(nat.isSuperPrime()) - natures.push_back(nat); - std::cout << "DDDDD" << std::endl; - } - } - ~Container() { - std::cout << "Destroy SuperPrime " << std::endl; - } - - SuperPrime max() { - std::vector::iterate it = natures.begin(); - Nature max(0); - for(; it != natures.end(); it ++) { - if (max.compare(*it)) { - max = *it; - } - } - return max; - } -}; + int main() { - SuperPrime sp(10, 13); - Nature n = sp.max(); - std::cout << "锟斤拷蟪锟斤拷锟斤拷锟斤拷锟" ; - //n.show(); + return 0; } From 22d9cee6ef96e96de5d3a133f0f50aebabaacc1b Mon Sep 17 00:00:00 2001 From: Biuviu <33221210+Biuviu@users.noreply.github.com> Date: Sun, 25 Apr 2021 19:32:25 +0800 Subject: [PATCH 47/89] Update SuperPrime_HW2.cpp --- SuperPrime_HW2.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/SuperPrime_HW2.cpp b/SuperPrime_HW2.cpp index ec1c77f3..8133518d 100644 --- a/SuperPrime_HW2.cpp +++ b/SuperPrime_HW2.cpp @@ -87,6 +87,7 @@ class Container { int main() { SuperPrime sp(10, 13); Nature n = sp.max(); + Nature n = sp.max(); std::cout << "锟斤拷蟪锟斤拷锟斤拷锟斤拷锟" ; n.show(); From 7e378fe44cf443f40ecc995df0d41844d082d78c Mon Sep 17 00:00:00 2001 From: Biuviu <33221210+Biuviu@users.noreply.github.com> Date: Sun, 25 Apr 2021 19:47:47 +0800 Subject: [PATCH 48/89] Update SuperPrime_HW2.cpp --- SuperPrime_HW2.cpp | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/SuperPrime_HW2.cpp b/SuperPrime_HW2.cpp index 8133518d..88f09974 100644 --- a/SuperPrime_HW2.cpp +++ b/SuperPrime_HW2.cpp @@ -85,11 +85,7 @@ class Container { } }; int main() { - SuperPrime sp(10, 13); - Nature n = sp.max(); - Nature n = sp.max(); - std::cout << "锟斤拷蟪锟斤拷锟斤拷锟斤拷锟" ; - n.show(); + return 0; } From b5efd1ac33e5436e4d99ac1a1602a6f801abfc24 Mon Sep 17 00:00:00 2001 From: Lake Hoo Date: Tue, 27 Apr 2021 18:29:05 +0800 Subject: [PATCH 49/89] Homework3 --- SuperPrime_HW3.cpp | 58 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 SuperPrime_HW3.cpp diff --git a/SuperPrime_HW3.cpp b/SuperPrime_HW3.cpp new file mode 100644 index 00000000..9a9f3a2c --- /dev/null +++ b/SuperPrime_HW3.cpp @@ -0,0 +1,58 @@ +#include +#include +class Nature { +protected: + int num; +public: + Nature(int n) { + num = n; + } + virtual bool isPrime() { + for(int i = 2; i < num;i++) { + if(num % i == 0) + return false; + } + return true; + } + void show() { + std::cout << num << std::endl; + } +}; +class SuperPrime:public Nature { +private: +public: + SuperPrime(int n):Nature(n) { + } + bool isPrime() { + int tmp = num + 1; + int sum = 0, mul = 1, sqr = 0; + while(tmp != 0) { + tmp = tmp / 10; + int x = tmp % 10; + sum += x; + mul *= x; + sqr += x*x; + } + Nature nat(sum), nat1(mul), nat2(sqr); + return Nature::isPrime() && nat.isPrime() && nat1.isPrime()&& nat2.isPrime(); + } +}; +int main() { + //create some objects + std::vector sps; + for (int i = 100; i < 999; i++) { + Nature *nat = new SuperPrime(i); + if (nat->isPrime()) + sps.push_back(nat); + } + std::vector::iterator it; + for(it=sps.begin(); it!=sps.end();it++) { + (*it)->show(); + } + for(it=sps.begin(); it!=sps.end();it++) { + delete *it; + } + + //最大的超级素数 + return 0; +} From f3b2a366ab0e788847c330f0be4c3a2bf0f536c4 Mon Sep 17 00:00:00 2001 From: Lake Hoo Date: Tue, 11 May 2021 18:31:02 +0800 Subject: [PATCH 50/89] Operator Overload --- Operator.cpp | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 Operator.cpp diff --git a/Operator.cpp b/Operator.cpp new file mode 100644 index 00000000..96ef7620 --- /dev/null +++ b/Operator.cpp @@ -0,0 +1,45 @@ +#include +class Parent { +public: + Parent(int n) { + flag = n; + std::cout << "Parent()" << flag << std::endl; + } + virtual ~Parent(){ + std::cout << "~~~Parent()" << flag << std::endl; + } + //other methods???? + void show(); +private: + //attributes?? + int flag; +}; +class Child : public Parent { +public: + Child(int n):Parent(n) { + flag = n; + std::cout << "Child()" << n << std::endl; + } + virtual ~Child(){ + std::cout << "~~~Child()" << flag << std::endl; + } + //other methods???? + //function object + void operator() (int n) { + } +private: + //attributes?? + int flag; + void operator= (const Child &c) { + std::cout << "operator = " << flag << std::endl; + } +}; +int main() { + Parent *p; + p = new Child(1); + Child c(2); + //c = Child(3); + //p->?????(); + delete p; + return 0; +} From 9c3ba0c8fd6966e6f5911f12529c65b24139c842 Mon Sep 17 00:00:00 2001 From: biuviu <1573560881@qq.com> Date: Fri, 14 May 2021 11:01:28 +0800 Subject: [PATCH 51/89] test --- FCdemo.cpp | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 FCdemo.cpp diff --git a/FCdemo.cpp b/FCdemo.cpp new file mode 100644 index 00000000..ec39b2e3 --- /dev/null +++ b/FCdemo.cpp @@ -0,0 +1,60 @@ +#include +#include +#include +#include +#include + +using namespace std; + +class Person +{ + public: + Person(string lastname, string firstname) + : _firstname(firstname) + , _lastname(lastname) + { + } + string firstname() const + { + return _firstname; + } + string lastname() const + { + return _lastname; + } + + private: + string _firstname = nullptr; + string _lastname = nullptr; +}; + +class PersonSortCriterion +{ + public: + bool operator()(const Person& p1, const Person& p2) const + { + return p1.lastname() < p2.lastname() || + (p1.lastname() == p2.lastname() && p1.firstname() < p2.firstname()); + } +}; + +int main(void) +{ + set coll; + Person p1("yu", "g"); + Person p2("an", "yu"); + Person p3("xiao", "ming"); + Person p4("xi", "biaoge"); + Person p5("u", "ong"); + coll.insert(p1); + coll.insert(p2); + coll.insert(p3); + coll.insert(p4); + coll.insert(p5); + for (auto i : coll) { + cout << i.lastname() << ", " << i.firstname() << endl; + } + + return 0; +} + From 0132086a77426879d940e6609fc34456eb31b4ec Mon Sep 17 00:00:00 2001 From: biuviu <1573560881@qq.com> Date: Fri, 14 May 2021 11:10:06 +0800 Subject: [PATCH 52/89] remove --- SuperPrime_HW.cpp | 7 ---- SuperPrime_HW2.cpp | 91 ---------------------------------------------- 2 files changed, 98 deletions(-) delete mode 100644 SuperPrime_HW.cpp delete mode 100644 SuperPrime_HW2.cpp diff --git a/SuperPrime_HW.cpp b/SuperPrime_HW.cpp deleted file mode 100644 index b6374190..00000000 --- a/SuperPrime_HW.cpp +++ /dev/null @@ -1,7 +0,0 @@ -#include -using namespace std; -int main() { - cout<<"hello"< -#include -class Nature { -private: - int num; -public: - Nature():num(0){ - std::cout << "Default Create Nature as " << num << std::endl; - } - Nature(int n):num(n) { - std::cout << "Create Nature as " << num << std::endl; - } - Nature(const Nature &nat):num(nat.num){ - std::cout << "Copy Create Nature as " << num << std::endl; - } - ~Nature() { - std::cout << "Destroy Nature as " << num << std::endl; - } - bool isPrime() { - if(num == 1 || num == 0) - return false; - for(int i = 2; i <= (int)sqrt(num); i++) - { - if(num % i == 0) - return false; - } - return true; - } - int compare(const Nature &nat) { - if (num > nat.num) - return 1; - else if(num == nat.num) - return 0; - - return -1; - } -private: -}; -class SuperPrime : public Nature { -private: - int num; -public: - SuperPrime(int n):num(n) { - } - bool isPrime() { - Nature nat(num); - return nat.isPrime(); - } - int compare(const SuperPrime &nat) { - if (num > nat.num) - return 1; - else if(num == nat.num) - return 0; - - return -1; - } -}; -class Container { -private: - std::vector natures; -public: - Container(int a, int b) { - std::cout << "Create SuperPrime from " << a << " to " << b << std::endl; - for(int i = a; i < b; i++) { - SuperPrime nat(i); - std::cout << "HAHA" << std::endl; - if(nat.isSuperPrime()) - natures.push_back(nat); - std::cout << "DDDDD" << std::endl; - } - } - ~Container() { - std::cout << "Destroy SuperPrime " << std::endl; - } - - SuperPrime max() { - std::vector::iterate it = natures.begin(); - Nature max(0); - for(; it != natures.end(); it ++) { - if (max.compare(*it)) { - max = *it; - } - } - return max; - } -}; -int main() { - - - return 0; -} From ab250344486102efd361722d53092dedac08b020 Mon Sep 17 00:00:00 2001 From: Biuviu <33221210+Biuviu@users.noreply.github.com> Date: Fri, 14 May 2021 11:28:54 +0800 Subject: [PATCH 53/89] Create SuperPrime_HW.cpp --- SuperPrime_HW.cpp | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 SuperPrime_HW.cpp diff --git a/SuperPrime_HW.cpp b/SuperPrime_HW.cpp new file mode 100644 index 00000000..0e004b50 --- /dev/null +++ b/SuperPrime_HW.cpp @@ -0,0 +1,5 @@ +#include + +int main() { + return 0; +} From d39122b87fde3e3a0d1e96636fadc448c84e6ee1 Mon Sep 17 00:00:00 2001 From: Biuviu <33221210+Biuviu@users.noreply.github.com> Date: Fri, 14 May 2021 11:29:35 +0800 Subject: [PATCH 54/89] Create SuperPrime_HW2.cpp --- SuperPrime_HW2.cpp | 94 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 94 insertions(+) create mode 100644 SuperPrime_HW2.cpp diff --git a/SuperPrime_HW2.cpp b/SuperPrime_HW2.cpp new file mode 100644 index 00000000..ec1c77f3 --- /dev/null +++ b/SuperPrime_HW2.cpp @@ -0,0 +1,94 @@ +#include +#include +class Nature { +private: + int num; +public: + Nature():num(0){ + std::cout << "Default Create Nature as " << num << std::endl; + } + Nature(int n):num(n) { + std::cout << "Create Nature as " << num << std::endl; + } + Nature(const Nature &nat):num(nat.num){ + std::cout << "Copy Create Nature as " << num << std::endl; + } + ~Nature() { + std::cout << "Destroy Nature as " << num << std::endl; + } + bool isPrime() { + if(num == 1 || num == 0) + return false; + for(int i = 2; i <= (int)sqrt(num); i++) + { + if(num % i == 0) + return false; + } + return true; + } + int compare(const Nature &nat) { + if (num > nat.num) + return 1; + else if(num == nat.num) + return 0; + + return -1; + } +private: +}; +class SuperPrime : public Nature { +private: + int num; +public: + SuperPrime(int n):num(n) { + } + bool isPrime() { + Nature nat(num); + return nat.isPrime(); + } + int compare(const SuperPrime &nat) { + if (num > nat.num) + return 1; + else if(num == nat.num) + return 0; + + return -1; + } +}; +class Container { +private: + std::vector natures; +public: + Container(int a, int b) { + std::cout << "Create SuperPrime from " << a << " to " << b << std::endl; + for(int i = a; i < b; i++) { + SuperPrime nat(i); + std::cout << "HAHA" << std::endl; + if(nat.isSuperPrime()) + natures.push_back(nat); + std::cout << "DDDDD" << std::endl; + } + } + ~Container() { + std::cout << "Destroy SuperPrime " << std::endl; + } + + SuperPrime max() { + std::vector::iterate it = natures.begin(); + Nature max(0); + for(; it != natures.end(); it ++) { + if (max.compare(*it)) { + max = *it; + } + } + return max; + } +}; +int main() { + SuperPrime sp(10, 13); + Nature n = sp.max(); + std::cout << "锟斤拷蟪锟斤拷锟斤拷锟斤拷锟" ; + n.show(); + + return 0; +} From 03f302774e0a59ee212cf04c3e6ed5237eae7a0f Mon Sep 17 00:00:00 2001 From: Lake Hoo Date: Tue, 18 May 2021 18:35:58 +0800 Subject: [PATCH 55/89] Function Object && const && static --- FCdemo.cpp | 67 ++++++++++++++++++++++++++++---------------------- StaticDemo.cpp | 44 +++++++++++++++++++++++++++++++++ 2 files changed, 82 insertions(+), 29 deletions(-) create mode 100644 StaticDemo.cpp diff --git a/FCdemo.cpp b/FCdemo.cpp index ec39b2e3..c443973e 100644 --- a/FCdemo.cpp +++ b/FCdemo.cpp @@ -1,46 +1,55 @@ #include #include #include +#include #include #include - +// -std=c++11 using namespace std; - +//constant class Person { - public: - Person(string lastname, string firstname) - : _firstname(firstname) - , _lastname(lastname) - { - } - string firstname() const - { - return _firstname; - } - string lastname() const - { - return _lastname; - } - - private: - string _firstname = nullptr; - string _lastname = nullptr; +public: + Person(string lastname, string firstname) + : _firstname(firstname), _lastname(lastname) + { + } + string firstname() const + { + return _firstname; + } + string lastname() const + { + return _lastname; + } +private: + const string _firstname = nullptr; + const string _lastname = nullptr; }; class PersonSortCriterion { - public: - bool operator()(const Person& p1, const Person& p2) const - { - return p1.lastname() < p2.lastname() || - (p1.lastname() == p2.lastname() && p1.firstname() < p2.firstname()); - } +public: + bool operator()(const Person &p1, const Person &p2) const + { + return p1.lastname() < p2.lastname() || + (p1.lastname() == p2.lastname() && p1.firstname() < p2.firstname()); + } +}; +class PersonSortCriterion1 +{ +public: + bool operator()(const Person &p1, const Person &p2) const + { + return p1.lastname() > p2.lastname() || + (p1.lastname() == p2.lastname() && p1.firstname() > p2.firstname()); + } }; int main(void) { - set coll; + set coll; + //unordered_set coll; Person p1("yu", "g"); Person p2("an", "yu"); Person p3("xiao", "ming"); @@ -51,10 +60,10 @@ int main(void) coll.insert(p3); coll.insert(p4); coll.insert(p5); - for (auto i : coll) { + for (auto i : coll) + { cout << i.lastname() << ", " << i.firstname() << endl; } return 0; } - diff --git a/StaticDemo.cpp b/StaticDemo.cpp new file mode 100644 index 00000000..9c3ceaa5 --- /dev/null +++ b/StaticDemo.cpp @@ -0,0 +1,44 @@ +#include +#include +using namespace std; +class Person +{ +public: + string firstname() const + { + return _firstname; + } + string lastname() const + { + return this->_lastname; + } + static int howmany() { + return counter; + } + static Person *create() { + return new Person("aa", "bb"); + } +private: + Person(string lastname, string firstname) + : _firstname(firstname), _lastname(lastname) + { + counter ++; + } + const string _firstname = nullptr; + const string _lastname = nullptr; + static int counter; +}; +int Person::counter = 0; +int main(void) +{ + Person *p1 = Person::create(); + Person p2("ou", "you"); + //how many person? + std::cout << Person::howmany() << std::endl; + cout << p1.howmany() << std::endl; + cout << p2.howmany() << std::endl; + Person p4("xi", "biaoge"); + + return 0; +} + From 875f947118edda540adb468143e0e6fdfb62f179 Mon Sep 17 00:00:00 2001 From: Your Name Date: Tue, 25 May 2021 18:30:58 +0800 Subject: [PATCH 56/89] =?UTF-8?q?=E5=AD=A6=E7=94=9F=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Student.cpp | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 Student.cpp diff --git a/Student.cpp b/Student.cpp new file mode 100644 index 00000000..5eed701a --- /dev/null +++ b/Student.cpp @@ -0,0 +1,52 @@ +#include +#include +#include +using namespace std; +class Student { +public: + Student(string &fn, string &ln, char s):sex(s) { + firstname = fn; + lastname = ln; + gpa = 0.0f; + grade = 1; + } + Student(const char fn[], const char ln[], char s):firstname(fn), lastname(ln), sex(s) { + gpa = 0.0f; + grade = 1; + } + ~Student() { + } + //method + void show_myself() { + std::cout << firstname << lastname << sex << grade << gpa << std::endl; + } + void study_time(int study_time) { + gpa = gpa + log(study_time); + gpa = gpa > 4.0f ? 4.0f : gpa; + } + int upgrade() { + int tmp = this->grade; + this->grade += 1; + this->grade = grade > 4 ? 4 : grade; + return tmp; + } +private: + float gpa; + std::string firstname, lastname; + char sex; + int grade; +}; + +int main() { + char buffer[5][100]={{"Mike", "Barnes", 'M'},{"Jim", "Nickerson", 'F'}} + string fn("Mike"), ln("Barnes"); + Student st1(fn, ln, 'M'), st2("Jim", "Nickerson", 'F'); + std::vector student_list; + student_list.push_pack(st1); + st1.upgrade(); + st1.study_time(60); + st2.study_time(1000); + st1.show_myself(); + st2.show_myself(); + return 0; +} From 08b51bd8037d4807660fac5c91b000ab6faf51ee Mon Sep 17 00:00:00 2001 From: Link-aka <1660306747@qq.com> Date: Wed, 23 Jun 2021 23:31:55 +0800 Subject: [PATCH 57/89] helloworld add commit --- xxf.cpp | 60 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 xxf.cpp diff --git a/xxf.cpp b/xxf.cpp new file mode 100644 index 00000000..6be38433 --- /dev/null +++ b/xxf.cpp @@ -0,0 +1,60 @@ + +#include +#include +#include +using namespace std; + +class Student +{ +private: + string name; //姓名 + char sex; //性别(男:M、女:F) + string grade; //年级 + float gpa; //绩点 +public: + Student(string n = "Unknown", char s = '?' , string gra = "Unknown", float g = 0) : + name(n), sex(s), grade(gra), gpa(g) {} + void show_myself(); //打印信息 + void study_time(float study_time); //增加GPA +}; + +void Student::show_myself() //打印信息 +{ + cout << "Name:" << name << endl; + cout << "Sex:" << sex << endl; + cout << "Grade:" << grade << endl; + cout << "GPA:" << gpa << endl; +} + +void Student::study_time(float study_time) //增加GPA +{ + gpa += log(study_time); + if (gpa > 4.0) gpa = 4.0; +} + +int main() +{ + Student Mike = { "Mike Barnes",'M',"Freshman",4 }; + Student Jim = { "Jim Nickerson",'M',"Dophomore",3 }; + Student Jack = { "Jack Indabox",'M',"Junior",2.5 }; + Student Jane = { "Jane Miller",'F',"Senior",3.6 }; + Student Mary = { "Mary Scott",'F',"Senior",2.7 }; + Student stu[5] = { Mike , Jim ,Jack ,Jane ,Mary }; + for (int i = 0; i < 5; i++) + { + stu[i].show_myself(); + cout << endl; + } + cout << "After studying......" << endl << endl; + int s_time[5] = { 60,100,40,300,1000 }; + for (int i = 0; i < 5; i++) + { + stu[i].study_time(s_time[i]); + stu[i].show_myself(); + cout << endl; + } + return 0; +} + + + From 5e493312fbfc3f112f2bcfa642c3e8c5696c53a5 Mon Sep 17 00:00:00 2001 From: Dashark Date: Sun, 26 Sep 2021 18:48:58 +0800 Subject: [PATCH 58/89] =?UTF-8?q?=E4=B8=A2=E5=A4=B1=E4=BA=86=E4=B8=8A?= =?UTF-8?q?=E4=B8=80=E4=B8=AA=E7=89=88=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Course-3.cpp | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 Course-3.cpp diff --git a/Course-3.cpp b/Course-3.cpp new file mode 100644 index 00000000..73d2328a --- /dev/null +++ b/Course-3.cpp @@ -0,0 +1,21 @@ +//姹備竴鍏冧簩娆℃柟绋嬬殑鏍 +// 渚嬪 锛歽 = x2 + 10x + 17 +// 褰 x = 2, 姹 y = 41 +// 褰 y = 2, 姹 x = ? +#include +#include +int main() { + float x1, x2; + float y, a, b, c; + printf("璇疯緭鍏ョ郴鏁帮細\n"); + scanf("%f, %f, %f, %f", &y, &a, &b, &c); + c = c - y; + a = 2 * a; + float temp = sqrt(b*b - 4* a*c); + x1 = (-b + temp)/(a); + x2 = (-b - temp)/(a); + printf("涓鍏冧簩娆℃柟绋嬫牴锛歕n"); + printf("%f\n", x1); //杩欐槸鍋氫粈涔堬紵 + printf("%f\n", x2); + return 0; +} From e6a14dfec7c2f7d2d703ee55b7e679d1931b82f6 Mon Sep 17 00:00:00 2001 From: Lake Hoo Date: Wed, 29 Sep 2021 14:33:13 +0800 Subject: [PATCH 59/89] Create leapyear1.cpp first version --- leapyear1.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 leapyear1.cpp diff --git a/leapyear1.cpp b/leapyear1.cpp new file mode 100644 index 00000000..aed60794 --- /dev/null +++ b/leapyear1.cpp @@ -0,0 +1,11 @@ +#include +int main() { + int year; + scanf("%d", &year); + if (year % 4 == 0 && year % 100 != 0 || year % 400 == 0) + if (year % 4 == 0 && !(year % 100 == 0) || year % 400 == 0) + printf("%d 年就是闰年\n", year); + else + printf("%d 年不是闰年\n", year); + return 0; +} From 25d61a80840241ee0b4de03c11644c6ca26465a4 Mon Sep 17 00:00:00 2001 From: Lake Hoo Date: Wed, 29 Sep 2021 15:03:07 +0800 Subject: [PATCH 60/89] Update leapyear1.cpp MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 鍙﹀涓鐗堟湰 --- leapyear1.cpp | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/leapyear1.cpp b/leapyear1.cpp index aed60794..a2c2c42c 100644 --- a/leapyear1.cpp +++ b/leapyear1.cpp @@ -2,10 +2,16 @@ int main() { int year; scanf("%d", &year); - if (year % 4 == 0 && year % 100 != 0 || year % 400 == 0) - if (year % 4 == 0 && !(year % 100 == 0) || year % 400 == 0) - printf("%d 年就是闰年\n", year); - else + if (year % 4 == 0) + if(year % 100 != 0) + printf("%d 年就是闰年\n", year); + else // year % 4 == 0 && year % 100 == 0 确定 year % 400 != 0? 、 + if(year % 400 == 0) + printf("%d 年就是闰年\n", year); + else + printf("%d 年不是闰年\n", year); + else //已知 year % 4 != 0 确定 year % 400 != 0 printf("%d 年不是闰年\n", year); + return 0; } From ee0adb0d0cab2787c501577dc63808faf2ba3612 Mon Sep 17 00:00:00 2001 From: Lake Hoo Date: Wed, 29 Sep 2021 15:12:52 +0800 Subject: [PATCH 61/89] Update leapyear1.cpp MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 鎺掔増娣蜂贡 --- leapyear1.cpp | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/leapyear1.cpp b/leapyear1.cpp index a2c2c42c..d7434b2f 100644 --- a/leapyear1.cpp +++ b/leapyear1.cpp @@ -3,15 +3,13 @@ int main() { int year; scanf("%d", &year); if (year % 4 == 0) - if(year % 100 != 0) + if (year % 100 != 0) printf("%d 年就是闰年\n", year); - else // year % 4 == 0 && year % 100 == 0 确定 year % 400 != 0? 、 - if(year % 400 == 0) + else if(year % 400 == 0) printf("%d 年就是闰年\n", year); - else + else printf("%d 年不是闰年\n", year); - else //已知 year % 4 != 0 确定 year % 400 != 0 + else printf("%d 年不是闰年\n", year); - return 0; } From 720688e8fd6fd22a1cfcaf8ba2a74d0f7b956daa Mon Sep 17 00:00:00 2001 From: Lake Hoo Date: Wed, 29 Sep 2021 15:16:15 +0800 Subject: [PATCH 62/89] Update leapyear1.cpp MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 缁忚繃VSCode鏍煎紡鍖 --- leapyear1.cpp | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/leapyear1.cpp b/leapyear1.cpp index d7434b2f..92fea092 100644 --- a/leapyear1.cpp +++ b/leapyear1.cpp @@ -1,15 +1,16 @@ #include -int main() { +int main() +{ int year; scanf("%d", &year); if (year % 4 == 0) - if (year % 100 != 0) - printf("%d 年就是闰年\n", year); - else if(year % 400 == 0) - printf("%d 年就是闰年\n", year); + if (year % 100 != 0) + printf("%d 年就是闰年\n", year); + else if (year % 400 == 0) + printf("%d 年就是闰年\n", year); + else + printf("%d 年不是闰年\n", year); else - printf("%d 年不是闰年\n", year); - else - printf("%d 年不是闰年\n", year); + printf("%d 年不是闰年\n", year); return 0; -} +} From ecc2342db1ff2cfbb2bdd7fea7dd5b4c5eed4109 Mon Sep 17 00:00:00 2001 From: Lake Hoo Date: Wed, 29 Sep 2021 15:21:13 +0800 Subject: [PATCH 63/89] Update leapyear1.cpp MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 閲嶆瀯鐗堟湰 --- leapyear1.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/leapyear1.cpp b/leapyear1.cpp index 92fea092..fd521533 100644 --- a/leapyear1.cpp +++ b/leapyear1.cpp @@ -4,8 +4,8 @@ int main() int year; scanf("%d", &year); if (year % 4 == 0) - if (year % 100 != 0) - printf("%d 年就是闰年\n", year); + if (year % 100 == 0) //Refine 重构 + printf("%d 年不是闰年\n", year); else if (year % 400 == 0) printf("%d 年就是闰年\n", year); else From 01acbaf733172b041e815c738a2e33728db32872 Mon Sep 17 00:00:00 2001 From: Lake Hoo Date: Wed, 29 Sep 2021 15:26:00 +0800 Subject: [PATCH 64/89] Update Course-3.cpp MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 淇敼涓枃涔辩爜鎻愮ず --- Course-3.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Course-3.cpp b/Course-3.cpp index 73d2328a..e9a1abb6 100644 --- a/Course-3.cpp +++ b/Course-3.cpp @@ -7,15 +7,15 @@ int main() { float x1, x2; float y, a, b, c; - printf("璇疯緭鍏ョ郴鏁帮細\n"); - scanf("%f, %f, %f, %f", &y, &a, &b, &c); + printf("Please input \n"); + scanf("%f %f %f %f", &y, &a, &b, &c); c = c - y; a = 2 * a; float temp = sqrt(b*b - 4* a*c); x1 = (-b + temp)/(a); x2 = (-b - temp)/(a); - printf("涓鍏冧簩娆℃柟绋嬫牴锛歕n"); - printf("%f\n", x1); //杩欐槸鍋氫粈涔堬紵 + printf("Results \n"); + printf("%f\n", x1); printf("%f\n", x2); return 0; } From 0315bf7e309b8fcc9838d4251d70eb98808197c7 Mon Sep 17 00:00:00 2001 From: Lake Hoo Date: Wed, 29 Sep 2021 16:01:38 +0800 Subject: [PATCH 65/89] Update Course-3.cpp MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 閲嶆瀯浜嗕唬鐮侀『搴 --- Course-3.cpp | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/Course-3.cpp b/Course-3.cpp index e9a1abb6..1118e759 100644 --- a/Course-3.cpp +++ b/Course-3.cpp @@ -6,16 +6,21 @@ #include int main() { float x1, x2; - float y, a, b, c; + float y, a, b, c, temp; printf("Please input \n"); scanf("%f %f %f %f", &y, &a, &b, &c); c = c - y; - a = 2 * a; - float temp = sqrt(b*b - 4* a*c); - x1 = (-b + temp)/(a); - x2 = (-b - temp)/(a); - printf("Results \n"); - printf("%f\n", x1); - printf("%f\n", x2); + temp = b*b - 4* a*c; + if(temp >= 0) { + temp = sqrt(temp); + a = 2 * a; + x1 = (-b + temp)/(a); + x2 = (-b - temp)/(a); + printf("Results \n"); + printf("%f\n", x1); + printf("%f\n", x2); + } + else + printf("No Results \n"); return 0; } From 2ddb020760a36d2d62a4905e367634fab04f87fc Mon Sep 17 00:00:00 2001 From: Lake Hoo Date: Wed, 29 Sep 2021 16:26:55 +0800 Subject: [PATCH 66/89] Update Course-3.cpp MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 閫氳繃寰幆鏂规硶姹傚钩鏂规牴 --- Course-3.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/Course-3.cpp b/Course-3.cpp index 1118e759..8979f3ce 100644 --- a/Course-3.cpp +++ b/Course-3.cpp @@ -4,6 +4,17 @@ // 褰 y = 2, 姹 x = ? #include #include +float mysqrt(float n) { + // how to guess + float x = n/2; + while(...) { + if (x*x > n) + x = x/2; + else + x = (x+n)/2; + } + return 0.0f; +} int main() { float x1, x2; float y, a, b, c, temp; From 1c0c0587f343fe2f3c85c0c44f3f1f2ec856dbb5 Mon Sep 17 00:00:00 2001 From: Nikhil <46191967+nikhilcse@users.noreply.github.com> Date: Sun, 17 Oct 2021 18:42:35 +0530 Subject: [PATCH 67/89] Updated spelling --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 942a6b1b..48be79d5 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# hello-world +# Hello-World C/C++缂栫▼鍒濆鑰 # Git鎵嬪唽 @@ -17,4 +17,4 @@ git log --author="$(git config --get user.name)" --pretty=tformat: --numstat | g git shortlog -s ``` -[Code Reference](https://github.com/WangShouDao/count_github_push) \ No newline at end of file +[Code Reference](https://github.com/WangShouDao/count_github_push) From 1bcf4ef7692c3b8c98aa3f1a48002509a3e8c504 Mon Sep 17 00:00:00 2001 From: Dashark Date: Fri, 29 Oct 2021 19:27:27 +0800 Subject: [PATCH 68/89] =?UTF-8?q?=E4=BD=9C=E4=B8=9A=E4=B8=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SuperPrime.c | 1 + 1 file changed, 1 insertion(+) diff --git a/SuperPrime.c b/SuperPrime.c index c418b363..ed445ae2 100644 --- a/SuperPrime.c +++ b/SuperPrime.c @@ -1,5 +1,6 @@ //瓒呯骇绱犳暟锛氬畠鏈韩锛屽悇浣嶆暟瀛楃殑鍜岋紝鍚勪綅鏁板瓧鐨勫钩鏂瑰拰锛岄兘鏄礌鏁般 //姹 100~10000 鍐呯殑鎵鏈夎秴绾х礌鏁帮紝鍙婂畠浠殑骞冲潎鏁般 +// 2021-10-29 int isPrime(int x); int splitNum(int x, int num[]); From 4167ca4a6afac1ce88d4ea2f22a4a82c20959300 Mon Sep 17 00:00:00 2001 From: Dashark Date: Fri, 29 Oct 2021 19:33:44 +0800 Subject: [PATCH 69/89] =?UTF-8?q?=E4=BD=9C=E4=B8=9A=E4=BA=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- PQPrime.c | 1 + PQPrime.md | 1 + 2 files changed, 2 insertions(+) create mode 100644 PQPrime.c create mode 100644 PQPrime.md diff --git a/PQPrime.c b/PQPrime.c new file mode 100644 index 00000000..04e32377 --- /dev/null +++ b/PQPrime.c @@ -0,0 +1 @@ +// 姹 p 鍜 q \ No newline at end of file diff --git a/PQPrime.md b/PQPrime.md new file mode 100644 index 00000000..0619e3b0 --- /dev/null +++ b/PQPrime.md @@ -0,0 +1 @@ +$p^q + q^p$鏄竴涓礌鏁帮紝姹$p$鍜$q$ \ No newline at end of file From c31d0243de269f8d6ea70477f4afa111b749e3b1 Mon Sep 17 00:00:00 2001 From: Dashark Date: Thu, 4 Nov 2021 10:05:59 +0800 Subject: [PATCH 70/89] =?UTF-8?q?=E4=BD=9C=E4=B8=9A=E4=B8=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- google.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/google.c b/google.c index 78198f79..ed0baba4 100644 --- a/google.c +++ b/google.c @@ -1,4 +1,5 @@ //f(n)鍑芥暟鐨勫畾涔変负0~n涓寘鍚殑1鐨勪釜鏁 //f(13)鏄0~13涓寘鍚1鐨勬湁 1锛10锛11锛12锛13锛屾墍浠(13)=6 //f(1) = 1銆 -//姹傚彟涓涓猣(n)=n鐨刵鍊 \ No newline at end of file +//姹傚彟涓涓猣(n)=n鐨刵鍊 +// 2021-11-04 \ No newline at end of file From 8f637c4458b90692d2eb0aca32dd31ace7663523 Mon Sep 17 00:00:00 2001 From: Dashark Date: Thu, 4 Nov 2021 10:06:13 +0800 Subject: [PATCH 71/89] =?UTF-8?q?=E4=BD=9C=E4=B8=9A=E5=9B=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- PQPrime.c | 3 ++- PQPrime.md | 4 +++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/PQPrime.c b/PQPrime.c index 04e32377..722c6409 100644 --- a/PQPrime.c +++ b/PQPrime.c @@ -1 +1,2 @@ -// 姹 p 鍜 q \ No newline at end of file +// 姹 p 鍜 q +// 褰 p 鍜 q 閮芥槸绱犳暟锛屾眰 p 鍜 q \ No newline at end of file diff --git a/PQPrime.md b/PQPrime.md index 0619e3b0..4ddcdc36 100644 --- a/PQPrime.md +++ b/PQPrime.md @@ -1 +1,3 @@ -$p^q + q^p$鏄竴涓礌鏁帮紝姹$p$鍜$q$ \ No newline at end of file +$p^q + q^p$鏄竴涓礌鏁帮紝 +$p$鍜$q$涔熸槸绱犳暟锛 +姹$p$鍜$q$ \ No newline at end of file From 439c582e363389a6ceef90a3163b6edabc54598c Mon Sep 17 00:00:00 2001 From: Dashark Date: Sun, 14 Nov 2021 18:21:36 +0800 Subject: [PATCH 72/89] =?UTF-8?q?=E4=BD=9C=E4=B8=9A=E4=BA=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- resolutions.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/resolutions.c b/resolutions.c index a159db27..e987807d 100644 --- a/resolutions.c +++ b/resolutions.c @@ -1,10 +1,10 @@ -//閫変綔棰 //杈撳叆涓涓瓧绗︿覆锛屽舰濡 //3072x1728,2720x1536,2560x1600,2560x1440,2304x1728,2048x1536,1920x1200,1920x1080,1440x900,1280x800,1280x720,1024x768,1024x640,800x600,800x500,800x450,640x480,640x400,640x360,480x360,480x300,480x270,320x240,320x200,320x180,240x180,176x144,160x120,160x100,160x90 //杩欐槸涓涓樉绀哄櫒鏀寔鐨勫垎杈ㄧ巼娓呭崟锛屼腑闂撮楀彿鍒嗛殧銆 //鐜板湪杈撳叆鐢婚潰鐨勫鍜岄珮锛岀劧鍚庡湪涓婅堪娓呭崟涓寫閫変竴涓渶鎺ヨ繎鐨勫垎杈ㄧ巼杈撳嚭 //姣斿杈撳叆2000锛1000锛岃緭鍑虹殑鍒嗚鲸鐜囧簲璇ユ槸1920x1080锛屽洜涓哄叾瀹冨垎杈ㄧ巼鐨勮宸洿澶с //瀹屾垚濡備笅绋嬪簭 +// 2021-11-14 #include int main() { @@ -13,6 +13,7 @@ int main() scanf("%s", ress); scanf("%d %d", &x, &y); + // 瀛︿範涓涓 sscanf 鍙互鏂逛究澶勭悊 ress 瀛楃涓 printf("閫変腑鐨勫垎杈ㄧ巼鏄%s\n", "???"); return 0; From 52c50496500918446e33513faf22337232c61a78 Mon Sep 17 00:00:00 2001 From: Dashark Date: Sun, 21 Nov 2021 10:06:57 +0800 Subject: [PATCH 73/89] =?UTF-8?q?=E4=BD=9C=E4=B8=9A=E5=85=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- convolution.c | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 convolution.c diff --git a/convolution.c b/convolution.c new file mode 100644 index 00000000..bdb092aa --- /dev/null +++ b/convolution.c @@ -0,0 +1,4 @@ +// 鍗风Н锛圕onvolution锛夋槸褰撳墠绁炵粡缃戠粶鐨勫熀纭绠楁硶 +// 鍗风Н鐨勫師鐞嗕笉澶嶆潅锛岀綉涓婃湁澶ч噺璧勬枡鍜屽疄鐜帮紝鍖呮嫭C璇█瀹炵幇 +// 澶у鑷璁捐涓涓嵎绉嚱鏁帮紝杈撳叆涓涓悜閲忓拰鍗风Н鏍革紝杈撳嚭鍗风Н鐨勭粨鏋 +// 2021-11-21 \ No newline at end of file From 17deb37c0e9611f80ced8e2d2e64af4748066021 Mon Sep 17 00:00:00 2001 From: Dashark Date: Tue, 21 Dec 2021 20:33:17 +0800 Subject: [PATCH 74/89] =?UTF-8?q?=E4=B8=80=E4=BA=9B=E8=AE=B0=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- homework.md | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 homework.md diff --git a/homework.md b/homework.md new file mode 100644 index 00000000..4847e1d7 --- /dev/null +++ b/homework.md @@ -0,0 +1,2 @@ +鏈変竴涓暟缁勶紝灏嗘弧瓒虫潯浠剁殑鍏冪礌鍒犻櫎锛岀劧鍚庡皢鍚庨潰鐨勫厓绱犲墠绉伙紝浣垮厓绱犱繚鎸佷緷搴忔帓鍒椼 +姣斿 1 3 5 3 8 ? ?锛屽垹闄 3锛屾渶鍚庡緱鍒 1 5 8 ? ? ? ? \ No newline at end of file From aa80457901011e45e5ed3adc710e3e849c7462a7 Mon Sep 17 00:00:00 2001 From: Dashark Date: Wed, 23 Mar 2022 10:31:04 +0800 Subject: [PATCH 75/89] =?UTF-8?q?SuperPrime=E5=AE=9E=E7=8E=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SuperPrime/Prime.cpp | 97 ++++++++++++++++++++++++++++++++++++++++++++ SuperPrime/Prime.h | 26 ++++++++++++ SuperPrime/README.md | 14 +++++++ SuperPrime/SP.wsd | 14 +++++++ SuperPrime/main.cpp | 19 +++++++++ 5 files changed, 170 insertions(+) create mode 100644 SuperPrime/Prime.cpp create mode 100644 SuperPrime/Prime.h create mode 100644 SuperPrime/README.md create mode 100644 SuperPrime/SP.wsd create mode 100644 SuperPrime/main.cpp diff --git a/SuperPrime/Prime.cpp b/SuperPrime/Prime.cpp new file mode 100644 index 00000000..884d8fec --- /dev/null +++ b/SuperPrime/Prime.cpp @@ -0,0 +1,97 @@ +#include"Prime.h" +#include + +Prime::Prime(int low , int high){ + for(int i = low ; i <= high ; i++){ + if(judgePrime(i)){ + p.push_back(i);//push杩涘鍣ㄤ腑 + } + } +} + +void Prime::showPrime(){ + for(int i = 0 ; i < p.size() ; i++){ + cout << p[i] << " ";//寰幆杈撳嚭 + } + cout << endl; +} + +int Prime::getSize(){ + return p.size();//鑾峰彇涓暟 +} + +//int *Prime::getPrime(){ +// int *arr = new int[p.size()];//鍔ㄦ佸垎閰嶆暟缁勪互瀛樺偍绱犳暟 +// for(int i = 0 ; i < p.size() ; i++){ +// arr[i] = p[i]; +// } +// return arr; +//} + +superPrime::superPrime(int low , int high){ + findPrime(low, high); +} + +//void superPrime::findsuperPrime(int low , int high){ +// Prime get;//鍒涘缓涓涓疄渚 +// get.findPrime(low , high); +// int *super = get.getPrime();//鑾峰緱瀛樻湁绱犳暟鐨勬暟缁 +// for(int i = 0 ; i < get.getSize() ; i++){ +// if(judgeSuperPrime(super[i])){//鍒ゆ柇鏄惁涓鸿秴绾х礌鏁 +// sp.push_back(super[i]); //push杩泇ector +// } +// } +// delete super; +//} + +void superPrime::findPrime(int low , int high){ + vector prime; + for(int i = low ; i <= high ; i++){ + if(Prime::judgePrime(i)){ + prime.push_back(i);//push杩涘鍣ㄤ腑 + } + } +// for(int i = 0 ; i < prime.size() ; i++){ +// cout << prime[i] << " "; +// } +// cout << prime.size() << endl; + for(int i = 0 ; i < prime.size() ; i++){ + if(superPrime::judgePrime(prime[i])){ + sp.push_back(prime[i]); + } + } +} + +void superPrime::showPrime(){ + for(int i = 0 ; i < sp.size() ; i++){ + cout << sp[i] << " "; + } + cout << endl; +} + +bool Prime::judgePrime(int a){ + if(a == 2){//2鍗曠嫭鍒ゆ柇 + return true; + } + for(int i = 2 ; i <= sqrt(a) + 1 ; i++){ + if(a % i == 0){ + return false; + } + } + return true; +} + +bool superPrime::judgePrime(int a){ + int eve[20] = {0} , i = 0 , sum = 0 , largesum = 0;//sum涓哄悇浣嶆暟鐨勫拰锛宭argesum鏄悇浣嶆暟骞虫柟鍜岋紝i鏄剼鏍 + while(a){//寰幆鎻愬彇鍚勪綅鏁 + eve[i] = a % 10; + sum += eve[i]; + largesum += eve[i] * eve[i]; + i++; + a /= 10; + } + if(Prime::judgePrime(sum) && Prime::judgePrime(largesum) && Prime::judgePrime(a)){ + return true; + } + return false; +} diff --git a/SuperPrime/Prime.h b/SuperPrime/Prime.h new file mode 100644 index 00000000..07dd5cf5 --- /dev/null +++ b/SuperPrime/Prime.h @@ -0,0 +1,26 @@ +#include +#include + +using namespace std; + +class Prime{ + public: + Prime(int low , int high);//鏋勯犲嚱鏁 + static bool judgePrime(int);//鍒ゆ柇涓涓暟鏄惁涓虹礌鏁 + void showPrime();//鎵撳嵃鍑烘墍閫夎寖鍥村唴鐨勬墍鏈夌礌鏁帮紝绌烘牸鍒嗛殧 + int getSize();//鑾峰彇绱犳暟涓暟 +// int *getPrime();//灏唙ector涓殑绱犳暟鏀惧叆涓涓暟缁勫苟杩斿洖棣栧湴鍧锛屼互渚泂uperPrime浣跨敤 + protected: + vector p;//瀹瑰櫒锛屽瓨鏀剧礌鏁 +}; + +class superPrime : public Prime { + public: + superPrime(int low , int high);//鏋勯犲嚱鏁 + void showPrime(); + private: + bool judgePrime(int);//鍒ゆ柇鏄惁涓鸿秴绾х礌鏁 + void findPrime(int , int);//鎵剧礌鏁帮紝鏀惧叆vector +}; + + diff --git a/SuperPrime/README.md b/SuperPrime/README.md new file mode 100644 index 00000000..5d15aa35 --- /dev/null +++ b/SuperPrime/README.md @@ -0,0 +1,14 @@ +- main.cpp 绋嬪簭鐨勫疄鐜颁唬鐮 +- Prime.h 绱犳暟鍜岃秴绾х礌鏁扮殑澹版槑浠g爜 +- Prime.cpp 绱犳暟鍜岃秴绾х礌鏁扮殑瀹炵幇浠g爜 +- SP.wsd PlantUML鐨勮剼鏈 + + +## [PlantUML](https://plantuml.com/zh/) +PlantUML鏄互鑴氭湰鏂瑰紡缂栧啓UML鐨勫伐鍏枫 + +鍙傝 *SP.wsd*锛屽畼缃戜笂鏈夎缁嗙殑鏂囨。璇存槑銆 + +鍙互鍦╒SCode涓畨瑁匬lantUML鎻掍欢 + +涔熷彲浠ョ洿鎺ヨ闂甗鍦ㄧ嚎缂栬緫鍣╙(https://www.plantuml.com/plantuml/uml/SyfFKj2rKt3CoKnELR1Io4ZDoSa70000) \ No newline at end of file diff --git a/SuperPrime/SP.wsd b/SuperPrime/SP.wsd new file mode 100644 index 00000000..8a7fd638 --- /dev/null +++ b/SuperPrime/SP.wsd @@ -0,0 +1,14 @@ +@startuml +class Prime { + +bool judgePrime() + +void showPrime() + +int getSize() + #vector p +} +class SuperPrime { + +bool judgePrime() + +void showPrime() + -void findPrime(int,int) +} +Prime <|-- SuperPrime +@enduml \ No newline at end of file diff --git a/SuperPrime/main.cpp b/SuperPrime/main.cpp new file mode 100644 index 00000000..9900a0d8 --- /dev/null +++ b/SuperPrime/main.cpp @@ -0,0 +1,19 @@ +#include"Prime.cpp" + +template +void func(Type a) +{ + //a.findPrime(100 , 999); + cout << "绱犳暟涓猴細" << endl; + a.showPrime(); +} +int main(){ + + Prime a(100,999); //寮哄埗鐨 + func(a); + + superPrime b(100,999); + func(b); + + return 0; +} From 262d6a774bc915638e4907c1c202bf034eec9d26 Mon Sep 17 00:00:00 2001 From: Dashark Date: Tue, 12 Apr 2022 10:12:35 +0800 Subject: [PATCH 76/89] =?UTF-8?q?=E8=AE=A1=E5=88=92=E6=90=9E=E4=B8=80?= =?UTF-8?q?=E4=B8=AA=E5=A4=A7=E7=BA=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Plan.md | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 Plan.md diff --git a/Plan.md b/Plan.md new file mode 100644 index 00000000..869038e6 --- /dev/null +++ b/Plan.md @@ -0,0 +1,15 @@ +# 8th Week +- OOD锛氱煩闃 + - 鏂规硶锛氬姞銆佸噺銆佺偣涔樸佸弶涔 + - 灞炴э細闅忎究 +- 鍔ㄤ綔锛氬鐢熻瑙d綔涓氾紙灞炰簬璇勪及锛 + +## Activities +1. 瀛︾敓璁茶В鐭╅樀浠g爜 +2. 鍒嗘瀽鐭╅樀鐨勫睘鎬у畾涔夛細鏁扮粍锛屽鍣紝Eigen瀹炵幇 +3. Eigen鐨勭户鎵匡細Curiously recurring template pattern 锛圕RTP锛夛紝濂囩壒鐨勯掑綊妯℃澘妯″紡 + 1. 棰犲掔户鎵匡紙Upside Down Inheritance锛夛紝瀹冪殑鏁堟灉涓庘滀紶缁熺户鎵挎槸閫氳繃娲剧敓绫诲悜鍩虹被娣诲姞鍔熻兘鈥濈殑搴旂敤姝eソ鐩稿弽鐨勩 + 2. 涓嶄娇鐢ㄨ櫄鍑芥暟浣嗘槸杈惧埌浜嗗鎬佺殑鏁堟灉锛屽ぇ閲忓簲鐢ㄤ簬鍚勭搴撲腑锛屾瘮濡侲igen搴擄紝WTL搴撱傚畠娌℃湁铏氬嚱鏁扮殑寮閿銆 +4. 灞曠ずEigen涓璏atrix鐨勬暟鎹粨鏋勶細瀹為檯涓婂睍绀轰笉涓嬪幓锛屾病娉曞仛 +5. 瀹為檯涓湅鏂囨。锛岃浠g爜锛岀収鏍蜂娇鐢‥igen搴撶紪绋嬨 +6. 閫氳繃璇绘簮浠g爜锛屽涔犱竴浜涙柊鎶鏈 \ No newline at end of file From d99c778f9b9157ce8e99b8a8e38d315c6c17cf4e Mon Sep 17 00:00:00 2001 From: Dashark Date: Wed, 13 Apr 2022 09:20:09 +0800 Subject: [PATCH 77/89] =?UTF-8?q?=E4=B8=80=E5=91=A8=E5=B0=8F=E7=BB=93?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Plan.md | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/Plan.md b/Plan.md index 869038e6..97d98958 100644 --- a/Plan.md +++ b/Plan.md @@ -12,4 +12,10 @@ 2. 涓嶄娇鐢ㄨ櫄鍑芥暟浣嗘槸杈惧埌浜嗗鎬佺殑鏁堟灉锛屽ぇ閲忓簲鐢ㄤ簬鍚勭搴撲腑锛屾瘮濡侲igen搴擄紝WTL搴撱傚畠娌℃湁铏氬嚱鏁扮殑寮閿銆 4. 灞曠ずEigen涓璏atrix鐨勬暟鎹粨鏋勶細瀹為檯涓婂睍绀轰笉涓嬪幓锛屾病娉曞仛 5. 瀹為檯涓湅鏂囨。锛岃浠g爜锛岀収鏍蜂娇鐢‥igen搴撶紪绋嬨 -6. 閫氳繃璇绘簮浠g爜锛屽涔犱竴浜涙柊鎶鏈 \ No newline at end of file +6. 閫氳繃璇绘簮浠g爜锛屽涔犱竴浜涙柊鎶鏈 + +## 缁撴灉 +鑷垜鎰熻鏁堟灉濂斤紝浜や簰澶皯锛屼互涓婂唴瀹规牴鏈病璁插畬銆侰RTP鍙浜嗗紑澶淬 + +# 9th Week +浣滀笟锛氬湪涓婂懆鐭╅樀鐨勫熀纭涓婏紝璁$畻娆ф皬璺濈锛屽懆鏈啀缁欍 \ No newline at end of file From f45b27e435d02f6e24dab42686e4865bfee00952 Mon Sep 17 00:00:00 2001 From: Dashark Date: Tue, 19 Apr 2022 11:37:22 +0800 Subject: [PATCH 78/89] =?UTF-8?q?=E7=AC=AC9=E5=91=A8=E8=AF=BE=E7=A8=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Plan.md | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/Plan.md b/Plan.md index 97d98958..79432b64 100644 --- a/Plan.md +++ b/Plan.md @@ -18,4 +18,17 @@ 鑷垜鎰熻鏁堟灉濂斤紝浜や簰澶皯锛屼互涓婂唴瀹规牴鏈病璁插畬銆侰RTP鍙浜嗗紑澶淬 # 9th Week -浣滀笟锛氬湪涓婂懆鐭╅樀鐨勫熀纭涓婏紝璁$畻娆ф皬璺濈锛屽懆鏈啀缁欍 \ No newline at end of file +浣滀笟锛氬湪涓婂懆鐭╅樀鐨勫熀纭涓婏紝璁$畻娆ф皬璺濈锛屽懆鏈啀缁欍 +鍛ㄦ湯蹇樿缁欎綔涓氾紝瀛︾敓璇存病鏃堕棿鍋氥 + +CRTP鐨勫鎬佹晥鏋滐紝涓庢爣鍑嗙殑澶氭佹瘮杈冦 +Matrix鐨勮繍绠楃閲嶈浇锛岀壒鍒槸()鐨勯噸杞姐 + +## Activities +1. 澶氭佺殑婕旂ず浠g爜銆備紭缂虹偣銆 +2. CRTP鐨勬紨绀轰唬鐮侊紝瀹炵幇鐩稿悓鐨勫鎬併傛墿灞晄tatic_cast +3. Eigen搴撲腑CRTP搴旂敤銆 +4. Matrix涓殑杩愮畻绗﹂噸杞姐 +5. ()鐨勯噸杞 + +## 缁撴灉 From 61d8904c605b034747591914006815e757a5ccf8 Mon Sep 17 00:00:00 2001 From: Dashark Date: Sun, 24 Apr 2022 11:21:58 +0800 Subject: [PATCH 79/89] =?UTF-8?q?Eigen=E7=9A=84=E7=B1=BB=E5=9B=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Eigen/plantuml | 16 ++++++++++++++++ Plan.md | 18 ++++++++++++++++++ 2 files changed, 34 insertions(+) create mode 100644 Eigen/plantuml diff --git a/Eigen/plantuml b/Eigen/plantuml new file mode 100644 index 00000000..c081c426 --- /dev/null +++ b/Eigen/plantuml @@ -0,0 +1,16 @@ +@startuml + +PlainObjectBase <|-- Matrix +PlainObjectBase <|-- Array + +MatrixBase <|-- PlainObjectBase +ArrayBase <|-- PlainObjectBase + +DenseBase <|-- MatrixBase +DenseBase <|-- ArrayBase + +DenseCoeffsBase <|-- DenseBase + +class EigenBase <> +EigenBase <|-- DenseCoeffsBase +@enduml \ No newline at end of file diff --git a/Plan.md b/Plan.md index 79432b64..8f9713fe 100644 --- a/Plan.md +++ b/Plan.md @@ -18,10 +18,13 @@ 鑷垜鎰熻鏁堟灉濂斤紝浜や簰澶皯锛屼互涓婂唴瀹规牴鏈病璁插畬銆侰RTP鍙浜嗗紑澶淬 # 9th Week + 浣滀笟锛氬湪涓婂懆鐭╅樀鐨勫熀纭涓婏紝璁$畻娆ф皬璺濈锛屽懆鏈啀缁欍 + 鍛ㄦ湯蹇樿缁欎綔涓氾紝瀛︾敓璇存病鏃堕棿鍋氥 CRTP鐨勫鎬佹晥鏋滐紝涓庢爣鍑嗙殑澶氭佹瘮杈冦 + Matrix鐨勮繍绠楃閲嶈浇锛岀壒鍒槸()鐨勯噸杞姐 ## Activities @@ -32,3 +35,18 @@ Matrix鐨勮繍绠楃閲嶈浇锛岀壒鍒槸()鐨勯噸杞姐 5. ()鐨勯噸杞 ## 缁撴灉 +璇剧▼鐨勫唴瀹规湁鐐规贩涔便 + +# 10th Week + +浣滀笟锛氬寛鐗欏埄绠楁硶 + +鏈懆鏃ヨˉ浜斾竴鐨勮绋嬶紝璁″垝鏈夌偣娣蜂贡浜嗐 + +鏈変釜瀛︾敓璺戝埆鐨勭彮鍚熀纭鍐呭浜嗭紝濂藉儚鎴戣寰楀唴瀹规湁鐐硅秴瓒婂鐢熺殑璁ょ煡浜嗐 + +## Activities +1. Eigen閲屼唬鐮佺殑缁ф壙鍏崇郴涓庡睍绀猴紝Matrix 鍜 Array +2. 鍏堟壘Eigen鏂囨。閲屽叧浜 Matrix 鍜 Array 鐨勮鏄 +3. 娓呯悊 Eigen 鐨勬簮浠g爜锛孋opy 鍑烘潵鍗曠嫭灞曠ず涓庤鏄 +4. 鐢讳竴涓 PlantUML 鐨勭畝瑕佹ā鍨 \ No newline at end of file From f4ccd700bfaaa72fb61934457ed98e1db3a470c9 Mon Sep 17 00:00:00 2001 From: Dashark Date: Mon, 25 Apr 2022 20:30:10 +0800 Subject: [PATCH 80/89] =?UTF-8?q?=E6=9C=89=E7=82=B9=E6=B7=B7=E6=B7=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Plan.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Plan.md b/Plan.md index 8f9713fe..ca656fde 100644 --- a/Plan.md +++ b/Plan.md @@ -49,4 +49,8 @@ Matrix鐨勮繍绠楃閲嶈浇锛岀壒鍒槸()鐨勯噸杞姐 1. Eigen閲屼唬鐮佺殑缁ф壙鍏崇郴涓庡睍绀猴紝Matrix 鍜 Array 2. 鍏堟壘Eigen鏂囨。閲屽叧浜 Matrix 鍜 Array 鐨勮鏄 3. 娓呯悊 Eigen 鐨勬簮浠g爜锛孋opy 鍑烘潵鍗曠嫭灞曠ず涓庤鏄 -4. 鐢讳竴涓 PlantUML 鐨勭畝瑕佹ā鍨 \ No newline at end of file +4. 鐢讳竴涓 PlantUML 鐨勭畝瑕佹ā鍨 + +# 11th Week + +澶氶噸缁ф壙涓 Mix in-class 缂栫▼ \ No newline at end of file From de13b94c939b982f821cae2ad72e49f8cfd9dc73 Mon Sep 17 00:00:00 2001 From: Dashark Date: Fri, 6 May 2022 16:26:54 +0800 Subject: [PATCH 81/89] =?UTF-8?q?=E5=A4=9A=E9=87=8D=E7=BB=A7=E6=89=BF?= =?UTF-8?q?=E4=B8=8E=E6=B7=B7=E6=9D=82=E6=A8=A1=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Mixins.java | 72 +++++++++++++++++++++++++++++++++++++++++++ multi-inheritance.cpp | 34 ++++++++++++++++++++ 2 files changed, 106 insertions(+) create mode 100644 Mixins.java create mode 100644 multi-inheritance.cpp diff --git a/Mixins.java b/Mixins.java new file mode 100644 index 00000000..d5773143 --- /dev/null +++ b/Mixins.java @@ -0,0 +1,72 @@ +/** + * 缁勫悎妯″紡 + * 鍦 TaggableImpl 涓疄鐜版墦鏍囩鐨勯昏緫 + * Post 绫诲拰 TaggableImpl 绫婚兘瀹炵幇 Taggable 鎺ュ彛 + * Post 绫讳腑鍒涘缓涓涓 TaggableImpl 瀹炰緥骞跺湪瀹炵幇 Taggable 鏃跺皢鐩稿簲鏂规硶璋冪敤濮旀墭杩囧幓銆 + */ + + +import java.util.List; +import java.util.ArrayList; + +interface Entity { + public int getId(); + public int getKind(); +} + +interface Taggable { + public void addTag(int tagId); + public List getTags(); +} + +class TaggableImpl implements Taggable { + private Entity target; + + public TaggableImpl(Entity target) { + this.target = target; + } + + public void addTag(int tagId) { + int id = target.getId(); + int kind = target.getKind(); + System.out.println("insert into ... values " + + id + ", " + + kind + ", " + + tagId + ")"); + } + + public ArrayList getTags() { + // query from database + return new ArrayList(); + } +} + +class Post implements Entity, Taggable { + public final static int KIND = 1001; + + private Taggable taggable; + private int id; + private String title; + + public Post(int id, String title) { + this.id = id; + this.title = title; + this.taggable = new TaggableImpl(this); + } + + public int getId() { + return id; + } + + public int getKind() { + return KIND; + } + + public void addTag(int tagId) { + taggable.addTag(tagId); // delegate + } + + public ArrayList getTags() { + return taggable.getTags(); // delegate + } +} \ No newline at end of file diff --git a/multi-inheritance.cpp b/multi-inheritance.cpp new file mode 100644 index 00000000..8749130c --- /dev/null +++ b/multi-inheritance.cpp @@ -0,0 +1,34 @@ +#include +using namespace std; +class Person { + // Data members of person +public: + Person(int x) { cout << "Person::Person(int ) called" << endl; } +}; + +class Faculty : public Person { + // data members of Faculty +public: + Faculty(int x):Person(x) { + cout<<"Faculty::Faculty(int ) called"<< endl; + } +}; + +class Student : public Person { + // data members of Student +public: + Student(int x):Person(x) { + cout<<"Student::Student(int ) called"<< endl; + } +}; + +class TA : public Faculty, public Student { +public: + TA(int x):Student(x), Faculty(x) { + cout<<"TA::TA(int ) called"<< endl; + } +}; + +int main() { + TA ta1(30); +} \ No newline at end of file From b20995dd88bf58e37e75a46a890dda8916a928ba Mon Sep 17 00:00:00 2001 From: Dashark Date: Tue, 10 May 2022 09:33:52 +0800 Subject: [PATCH 82/89] =?UTF-8?q?Mixins=E5=92=8CCRTP=E7=9A=84=E5=A4=A7?= =?UTF-8?q?=E7=BA=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Plan.md | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/Plan.md b/Plan.md index ca656fde..de37878f 100644 --- a/Plan.md +++ b/Plan.md @@ -53,4 +53,29 @@ Matrix鐨勮繍绠楃閲嶈浇锛岀壒鍒槸()鐨勯噸杞姐 # 11th Week -澶氶噸缁ф壙涓 Mix in-class 缂栫▼ \ No newline at end of file +澶氶噸缁ф壙涓 Mix in-class 缂栫▼ + +## Activities + +1. C++鐨勫閲嶇户鎵夸唬鐮佸睍绀 +2. Java鐗堟湰鐨凪ixins妯″紡浠g爜灞曠ず + +## 缁撴灉 + +浼拌鍚屽浠病鏈夊惉鎳 + +# 12th Week + +浣滀笟锛氭妸Java鐗堟湰鐨凪ixins鍐欐垚C++鐗堟湰鐨勩 + +## Activities + +1. 璁茶ВC++鐗堟湰鐨凪ixins浠g爜 +2. 灏咰++鐨勫閲嶇户鎵块噸鏋勪负妯℃澘绫荤殑缁ф壙 + 1. Persons浣滀负Students鐨勫熀绫伙紝鍏锋湁瀛︿範鐨勮兘鍔涖係tudents + 2. Faculties浣滀负Persons鐨勫瓙绫伙紝鍏锋湁鏁欎功鐨勮兘鍔涖侳aculties + 3. TAs鏈川鏄鐢燂紝鍏锋湁Faculties鐨勬暀涔﹁兘鍔涖侳aculties> +3. 灏咰RTP鐨勮璁″簲鐢 + 1. Persons灏辨槸Students銆 + 2. Persons灏辨槸Faculties銆 + 3. Persons涔熸槸TAs锛孲tudents灏辨槸TAs锛孴As涔熸槸Faculties銆 \ No newline at end of file From 51f57866e9fb87fcd7bf691325ad7c2981e51fc5 Mon Sep 17 00:00:00 2001 From: Dashark Date: Fri, 13 May 2022 18:47:30 +0800 Subject: [PATCH 83/89] Mixins with CRTP --- multi-inheritance.cpp | 75 +++++++++++++++++++++++++++++++++++++++---- 1 file changed, 68 insertions(+), 7 deletions(-) diff --git a/multi-inheritance.cpp b/multi-inheritance.cpp index 8749130c..40d7af37 100644 --- a/multi-inheritance.cpp +++ b/multi-inheritance.cpp @@ -1,34 +1,95 @@ #include using namespace std; + +template class Person { // Data members of person public: Person(int x) { cout << "Person::Person(int ) called" << endl; } + void learn() { + static_cast(*this).learn(); + } + void teach() { + static_cast(*this).teach(); + } }; - -class Faculty : public Person { + +template +class Faculty : public Person { // data members of Faculty public: Faculty(int x):Person(x) { cout<<"Faculty::Faculty(int ) called"<< endl; } + void learn() { + cout << "Faculty learn sth." << endl; + } + void teach() { + cout << "Faculty teach sth." << endl; + } }; - -class Student : public Person { + +template +class Student : public Person { // data members of Student public: Student(int x):Person(x) { cout<<"Student::Student(int ) called"<< endl; } + void learn() { + cout << "Student learn sth." << endl; + } + void teach() { + cout << "Student can't teach." << endl; + } }; - -class TA : public Faculty, public Student { +/* +template +class TA : public T1 { + TA(int x):T1(x) { + cout << "TA::TA(int ) called" << endl; + } + void learn() { + T1::learn(); + } + void teach() { + static_cast(*this).teach(); + } + // TA constraints +}; +*/ + +class TA : public Person { +public: + TA(int x):st(x), fa(x) { + cout << "TA::TA(int ) called" << endl; + } + void learn() { + st.learn(); + } + void teach() { + fa.teach(); + } +private: + Student st; + Faculty fa; +}; +class TA : public Student, public Faculty { public: TA(int x):Student(x), Faculty(x) { - cout<<"TA::TA(int ) called"<< endl; + cout << "TA::TA(int ) called" << endl; + } + void learn() { + Student::learn(); + } + void teach() { + Faculty::teach(); } }; int main() { TA ta1(30); + //TA ta1(30); + ta1.learn(); // Student's learn + ta1.teach(); // Faculty's teach } \ No newline at end of file From 23ecb6786ec9bfa350bef9a00bbc4277f2ab5485 Mon Sep 17 00:00:00 2001 From: Dashark Date: Tue, 17 May 2022 11:49:09 +0800 Subject: [PATCH 84/89] =?UTF-8?q?=E6=8E=A5=E5=8F=A3=E5=8F=98=E6=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SuperPrime/Prime.h | 9 +++++--- SuperPrime/main.cpp | 56 ++++++++++++++++++++++++++++++++++++++------- 2 files changed, 54 insertions(+), 11 deletions(-) diff --git a/SuperPrime/Prime.h b/SuperPrime/Prime.h index 07dd5cf5..3997ef95 100644 --- a/SuperPrime/Prime.h +++ b/SuperPrime/Prime.h @@ -6,7 +6,9 @@ using namespace std; class Prime{ public: Prime(int low , int high);//鏋勯犲嚱鏁 - static bool judgePrime(int);//鍒ゆ柇涓涓暟鏄惁涓虹礌鏁 + Prime(int n); + bool judgePrime(int);//鍒ゆ柇涓涓暟鏄惁涓虹礌鏁 + virtual bool isPrime(); void showPrime();//鎵撳嵃鍑烘墍閫夎寖鍥村唴鐨勬墍鏈夌礌鏁帮紝绌烘牸鍒嗛殧 int getSize();//鑾峰彇绱犳暟涓暟 // int *getPrime();//灏唙ector涓殑绱犳暟鏀惧叆涓涓暟缁勫苟杩斿洖棣栧湴鍧锛屼互渚泂uperPrime浣跨敤 @@ -17,9 +19,10 @@ class Prime{ class superPrime : public Prime { public: superPrime(int low , int high);//鏋勯犲嚱鏁 - void showPrime(); + superPrime(int n); + virtual bool isPrime(); private: - bool judgePrime(int);//鍒ゆ柇鏄惁涓鸿秴绾х礌鏁 + bool judgePrime(int);//鍒ゆ柇鏄惁涓鸿秴绾х礌鏁 void findPrime(int , int);//鎵剧礌鏁帮紝鏀惧叆vector }; diff --git a/SuperPrime/main.cpp b/SuperPrime/main.cpp index 9900a0d8..a90b3936 100644 --- a/SuperPrime/main.cpp +++ b/SuperPrime/main.cpp @@ -1,19 +1,59 @@ #include"Prime.cpp" template -void func(Type a) +void func(const Type &a) { //a.findPrime(100 , 999); cout << "绱犳暟涓猴細" << endl; a.showPrime(); } + +void func(Prime *p) +{ + cout << "绱犳暟涓猴細" << endl; + p->showPrime(); +} +void prime(int a, int b) +{ + std::vector ps; + for (int i = 100; i < 999; ++i) { + Prime * p = new Prime(i); + if (p->isPrime()) + ps.push_back(p); + else + delete p; + } + for (Prime *p : ps) { + p->showPrime(); + delete p; + } +} +void superprime(int a, int b) +{ + std::vector ps; + for (int i = 100; i < 999; ++i) { + Prime * p = new SuperPrime(i); + if (p->isPrime()) + ps.push_back(p); + else + delete p; + } + for (Prime *p : ps) { + p->showPrime(); + delete p; + } +} int main(){ - - Prime a(100,999); //寮哄埗鐨 - func(a); - - superPrime b(100,999); - func(b); - + + Prime pm(100, 999); + func(pm); + func(&pm); + + SuperPrime sp(100, 999); + func(sp); + func(&sp); + + prime(100, 999); + superprime(100, 999); return 0; } From 3d790c0ba492126f8ef843a4f6bcca0724b20390 Mon Sep 17 00:00:00 2001 From: Lake Hu Date: Tue, 18 Oct 2022 14:16:43 +0800 Subject: [PATCH 85/89] =?UTF-8?q?=E4=BA=A4=E6=8D=A2=E4=B8=A4=E4=B8=AA?= =?UTF-8?q?=E5=8F=98=E9=87=8F=E7=9A=84=E5=80=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- HelloWorld.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/HelloWorld.c b/HelloWorld.c index 3c79b6c5..d526b2d5 100644 --- a/HelloWorld.c +++ b/HelloWorld.c @@ -1,7 +1,11 @@ #include int main() { - printf("Hello World!\n"); - -//try Jenkins again + int x, y, temp; + // 交换两个变量的值 + scanf("%d %d", &x, &y); + temp = x; // Copy 一份 + x = y; // Copy y + y = temp; // 把x的拷贝赋值给y + printf("x = %d, y = %d", x, y); return 0; } From 7ca2fbbe5b24d7ed705615965a00c3614c3074f4 Mon Sep 17 00:00:00 2001 From: Lake Hu Date: Tue, 18 Oct 2022 14:25:27 +0800 Subject: [PATCH 86/89] =?UTF-8?q?=E5=81=9A=E4=BA=86=E4=B8=80=E4=B8=AA?= =?UTF-8?q?=E8=B4=BE=E4=BB=A3=E9=A9=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- HelloWorld.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/HelloWorld.c b/HelloWorld.c index d526b2d5..477686e4 100644 --- a/HelloWorld.c +++ b/HelloWorld.c @@ -3,9 +3,6 @@ int main() { int x, y, temp; // 交换两个变量的值 scanf("%d %d", &x, &y); - temp = x; // Copy 一份 - x = y; // Copy y - y = temp; // 把x的拷贝赋值给y - printf("x = %d, y = %d", x, y); + printf("x = %d, y = %d", y, x); return 0; } From 84ade2ab32b6ffd9a7bef59e293c646b7d3d5a2a Mon Sep 17 00:00:00 2001 From: Lake Hu Date: Tue, 18 Oct 2022 14:58:09 +0800 Subject: [PATCH 87/89] =?UTF-8?q?=E6=9D=A1=E4=BB=B6=E8=AF=AD=E5=8F=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- HelloWorld.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/HelloWorld.c b/HelloWorld.c index 477686e4..53b66648 100644 --- a/HelloWorld.c +++ b/HelloWorld.c @@ -1,8 +1,13 @@ #include int main() { - int x, y, temp; - // 交换两个变量的值 + int x, y, z, temp; + // 输入两个变量,按照从大到小输出 scanf("%d %d", &x, &y); - printf("x = %d, y = %d", y, x); + if ( x < y ) { + temp = x; // Copy 一份 + x = y; // Copy y + y = temp; // 把x的拷贝赋值给y + } + printf("x = %d, y = %d", x, y); return 0; } From e00b07aa9604bbf7dc791f0dc65dc4480974e469 Mon Sep 17 00:00:00 2001 From: Lake Hu Date: Tue, 18 Oct 2022 16:26:22 +0800 Subject: [PATCH 88/89] =?UTF-8?q?=E6=9D=A1=E4=BB=B6=E6=8E=92=E5=BA=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- HelloWorld.c | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/HelloWorld.c b/HelloWorld.c index 53b66648..2b1aa1e7 100644 --- a/HelloWorld.c +++ b/HelloWorld.c @@ -1,13 +1,23 @@ #include int main() { int x, y, z, temp; - // 输入两个变量,按照从大到小输出 - scanf("%d %d", &x, &y); - if ( x < y ) { - temp = x; // Copy 一份 - x = y; // Copy y - y = temp; // 把x的拷贝赋值给y + // 输入三个变量,按照从大到小输出 + scanf("%d %d %d", &x, &y, &z); + if ( y < z ) { + temp = y; + y = z; + z = temp; } - printf("x = %d, y = %d", x, y); + else if ( x < y ) { + temp = x; + x = y; + y = temp; + } + else if ( y < z ) { + temp = y; + y = z; + z = temp; + } + printf("%d, %d, %d\n", x, y, z); return 0; } From c22611ab74d202d95cb3c2a765fdb1370717f206 Mon Sep 17 00:00:00 2001 From: Lake Hu Date: Thu, 22 Dec 2022 20:56:41 +0800 Subject: [PATCH 89/89] =?UTF-8?q?=E6=9C=9F=E6=9C=AB=E8=80=83=E8=AF=95?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- round-robin.cpp | 93 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 93 insertions(+) create mode 100644 round-robin.cpp diff --git a/round-robin.cpp b/round-robin.cpp new file mode 100644 index 00000000..6aaa9d1e --- /dev/null +++ b/round-robin.cpp @@ -0,0 +1,93 @@ +#include +#include +int main() { + int n, i; + char teams[1000][50]; // 二维数组 + int score[1000]={0}, pure[1000]={0}; + int champin[1000]; + // 输入代码 + scanf("%d", &n); + for(i = 0; i < n; i+=1) + scanf("%s", teams[i]); + gets(teams[999]); + for(i = 0; i < n*(n-1)/2; i+=1) { + char match[1000]; + char t1[50], t2[50]; + int s1, s2, j = 0; + int t1_index, t2_index; + //scanf("%s", match); + gets(match); + printf("%s\n", match); + while(match[j] != 0) { + if (match[j] == '-' || match[j] == ':') + match[j] = ' '; + j += 1; + } + // printf("%s\n", match); + // 不断地累积积分和净得分 + sscanf(match, "%s %s %d %d", t1, t2, &s1, &s2); + printf("%s vs. %s == %d vs. %d \n", t1, t2, s1, s2); + for(j = 0; j < n; j += 1) { + if (strcmp(teams[j], t1) == 0) + t1_index = j; + if (strcmp(teams[j], t2) == 0) + t2_index = j; + } + if (s1 > s2) { + score[t1_index] += 3; + score[t2_index] += 0; + pure[t1_index] += s1 - s2; + pure[t2_index] -= s1 - s2; + } + else if (s1 == s2) { + score[t1_index] += 1; + score[t2_index] += 1; + pure[t1_index] += 0; + pure[t2_index] += 0; + } + else { + score[t1_index] += 0; + score[t2_index] += 3; + pure[t2_index] += s2 - s1; + pure[t1_index] -= s2 - s1; + } + } + for(i = 0; i < n; i += 1) { + //printf("%s, %d, %d\n", teams[i], score[i], pure[i]); + champin[i] = i; + } + for(i = 0; i < n-1; i+=1) { + for(int j = i+1; j < n; j+=1){ + if (score[champin[i]] < score[champin[j]]) { + int temp = champin[i]; + champin[i] = champin[j]; + champin[j] = temp; + } + else if (score[champin[i]] == score[champin[j]]) { + if (pure[champin[i]] < pure[champin[j]]) { + int temp = champin[i]; + champin[i] = champin[j]; + champin[j] = temp; + } + else if (pure[champin[i]] == pure[champin[j]]) { + //??? + } + } + } + } + int seq = 0; + for(i = 0; i < n; i += 1) { + //printf("%s, %d, %d\n", teams[i], score[i], pure[i]); + if (i == 0) { + printf("%s, %d\n", teams[champin[i]], seq);//score[champin[i]], pure[champin[i]]); + continue; + } + if (score[champin[i]] == score[champin[i-1]] && pure[champin[i]] == pure[champin[i-1]]) + printf("%s, %d\n", teams[champin[i]], seq);//score[champin[i]], pure[champin[i]]); + else { + seq += 1; + printf("%s, %d\n", teams[champin[i]], seq);//score[champin[i]], pure[champin[i]]); + } + } + return 0; +}