From 298d131e8a540979e257b342c897fbe38c9596c5 Mon Sep 17 00:00:00 2001 From: Time-wen <80614737+Time-wen@users.noreply.github.com> Date: Mon, 29 Mar 2021 08:32:08 +0800 Subject: [PATCH 01/12] Add files via upload --- ...205\347\272\247\347\264\240\346\225\260.c" | 103 ++++++++++++++++++ 1 file changed, 103 insertions(+) create mode 100644 "hw.1.2\350\266\205\347\272\247\347\264\240\346\225\260.c" diff --git "a/hw.1.2\350\266\205\347\272\247\347\264\240\346\225\260.c" "b/hw.1.2\350\266\205\347\272\247\347\264\240\346\225\260.c" new file mode 100644 index 00000000..75822aef --- /dev/null +++ "b/hw.1.2\350\266\205\347\272\247\347\264\240\346\225\260.c" @@ -0,0 +1,103 @@ +#include +//sum <= 27 mul <= 729 mul2 <= 243 +int main(){ + int p[1000] = {0}; + int pp[1000] = {0}; + int i = 2; + for(;i < 1000;i++){//筛数法 + p[i] = i; + } + + int j = 0; + i = 2; + for(; i < 1000;i++){//生成一个纯净的素数数组 + if(p[i] == 0){ + continue; + } + pp[j] = p[i]; + + //printf("A%d %d\n",pp[j],j); + + j++; + int k = 2; + for(;(i * k) < 1000;k++){ + p[i * k] = 0; + } + } + int ppn = j; + + //printf("B%d\n",ppn); + + //for(i = 0; i < j;i++){ + // printf("C%d %d\n",pp[i],i); + //} + + + int sp; + int countsp = 0; + int sumsp = 0; + int max = 0; + int judge = 0; + int t; + for(t = 25; t < ppn;t++){ + + //printf("D%d\n",pp[t]); + + sp = pp[t]; + int g = sp % 10; + int s = (sp - g) % 100 / 10; + int b = (sp - 10 * s - g) / 100; + int sum = g + s + b; + int mul = g * s * b; + int mul2 = g * g + s * s + b * b; + + //printf("E%d %d %d %d \n",sp,g,s,b); + + judge = 0; + for(j = 0;j < ppn;j++){ + if(pp[j] == sum){ + judge++; + + //printf("Q1\n"); + + break; + } + } + + //printf("go\n"); + + for(j = 0;j < ppn;j++){ + if(pp[j] == mul){ + judge++; + + //printf("Q2\n"); + + break; + } + } + ; + for(j = 0;j < ppn;j++){ + if(pp[j] == mul2){ + judge++; + + //printf("Q3\n"); + + break; + } + } + + if(judge == 3){ + countsp++; + sumsp += sp; + max = sp; + + printf("Q%d\n",sp); + + } + + } + printf("个数:%d 和:%d 最大:%d\n",countsp,sumsp,max); + + + return 0; +} From 5dfc8e2e38a08898f62b56878c1c019a816b4ca3 Mon Sep 17 00:00:00 2001 From: Time-wen <80614737+Time-wen@users.noreply.github.com> Date: Tue, 30 Mar 2021 10:22:05 +0800 Subject: [PATCH 02/12] =?UTF-8?q?=E7=94=B0=E6=96=87=E7=92=A7=2020201414603?= =?UTF-8?q?71=20=E8=B6=85=E7=BA=A7=E7=B4=A0=E6=95=B0.c?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- "hw.1.2\350\266\205\347\272\247\347\264\240\346\225\260.c" | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git "a/hw.1.2\350\266\205\347\272\247\347\264\240\346\225\260.c" "b/hw.1.2\350\266\205\347\272\247\347\264\240\346\225\260.c" index 75822aef..7d7f2634 100644 --- "a/hw.1.2\350\266\205\347\272\247\347\264\240\346\225\260.c" +++ "b/hw.1.2\350\266\205\347\272\247\347\264\240\346\225\260.c" @@ -91,12 +91,12 @@ int main(){ sumsp += sp; max = sp; - printf("Q%d\n",sp); + //printf("Q%d\n",sp); } } - printf("个数:%d 和:%d 最大:%d\n",countsp,sumsp,max); + printf("个数:%d 和:%d 最大:%d \n",countsp,sumsp,max); return 0; From 6b66bc67c5ab041fcec6a1f0c1074afbfd0f297f Mon Sep 17 00:00:00 2001 From: Time_wen <1149699397@qq.com> Date: Mon, 5 Apr 2021 21:24:38 +0800 Subject: [PATCH 03/12] commit amy --- amy/hw.1.2.superprime.c.c | 103 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 103 insertions(+) create mode 100644 amy/hw.1.2.superprime.c.c diff --git a/amy/hw.1.2.superprime.c.c b/amy/hw.1.2.superprime.c.c new file mode 100644 index 00000000..cfb21e14 --- /dev/null +++ b/amy/hw.1.2.superprime.c.c @@ -0,0 +1,103 @@ +#include +//sum <= 27 mul <= 729 mul2 <= 243 +int main(){ + int p[1000] = {0}; + int pp[1000] = {0}; + int i = 2; + for(;i < 1000;i++){//筛数法 + p[i] = i; + } + + int j = 0; + i = 2; + for(; i < 1000;i++){//生成一个纯净的素数数组 + if(p[i] == 0){ + continue; + } + pp[j] = p[i]; + + //printf("A%d %d\n",pp[j],j); + + j++; + int k = 2; + for(;(i * k) < 1000;k++){ + p[i * k] = 0; + } + } + int ppn = j; + + //printf("B%d\n",ppn); + + //for(i = 0; i < j;i++){ + // printf("C%d %d\n",pp[i],i); + //} + + + int sp; + int countsp = 0; + int sumsp = 0; + int max = 0; + int judge = 0; + int t; + for(t = 25; t < ppn;t++){ + + //printf("D%d\n",pp[t]); + + sp = pp[t]; + int g = sp % 10; + int s = (sp - g) % 100 / 10; + int b = (sp - 10 * s - g) / 100; + int sum = g + s + b; + int mul = g * s * b; + int mul2 = g * g + s * s + b * b; + + //printf("E%d %d %d %d \n",sp,g,s,b); + + judge = 0; + for(j = 0;j < ppn;j++){ + if(pp[j] == sum){ + judge++; + + //printf("Q1\n"); + + break; + } + } + + //printf("go\n"); + + for(j = 0;j < ppn;j++){ + if(pp[j] == mul){ + judge++; + + //printf("Q2\n"); + + break; + } + } + ; + for(j = 0;j < ppn;j++){ + if(pp[j] == mul2){ + judge++; + + //printf("Q3\n"); + + break; + } + } + + if(judge == 3){ + countsp++; + sumsp += sp; + max = sp; + + //printf("Q%d\n",sp); + + } + + } + printf("个数:%d 和:%d 最大:%d \n",countsp,sumsp,max); + + + return 0; +} From f66c1ee9910c78e48aa1acea0fb49c610209c354 Mon Sep 17 00:00:00 2001 From: Time-wen <80614737+Time-wen@users.noreply.github.com> Date: Tue, 6 Apr 2021 10:22:47 +0800 Subject: [PATCH 04/12] Update SuperPrime_HW.cpp --- SuperPrime_HW.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/SuperPrime_HW.cpp b/SuperPrime_HW.cpp index 0e004b50..68354b6f 100644 --- a/SuperPrime_HW.cpp +++ b/SuperPrime_HW.cpp @@ -1,5 +1,6 @@ #include - +#include int main() { + return 0; } From 5ad2eb32a52689c1844c3977fcfc519d12eedb6d Mon Sep 17 00:00:00 2001 From: Time-wen <80614737+Time-wen@users.noreply.github.com> Date: Tue, 6 Apr 2021 10:24:32 +0800 Subject: [PATCH 05/12] Update SuperPrime_HW.cpp --- SuperPrime_HW.cpp | 102 +++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 101 insertions(+), 1 deletion(-) diff --git a/SuperPrime_HW.cpp b/SuperPrime_HW.cpp index 68354b6f..f14dd768 100644 --- a/SuperPrime_HW.cpp +++ b/SuperPrime_HW.cpp @@ -1,6 +1,106 @@ #include #include int main() { - + #include +//sum <= 27 mul <= 729 mul2 <= 243 +int main(){ + int p[1000] = {0}; + int pp[1000] = {0}; + int i = 2; + for(;i < 1000;i++){//绛涙暟娉 + p[i] = i; + } + + int j = 0; + i = 2; + for(; i < 1000;i++){//鐢熸垚涓涓函鍑鐨勭礌鏁版暟缁 + if(p[i] == 0){ + continue; + } + pp[j] = p[i]; + + //printf("A%d %d\n",pp[j],j); + + j++; + int k = 2; + for(;(i * k) < 1000;k++){ + p[i * k] = 0; + } + } + int ppn = j; + + //printf("B%d\n",ppn); + + //for(i = 0; i < j;i++){ + // printf("C%d %d\n",pp[i],i); + //} + + + int sp; + int countsp = 0; + int sumsp = 0; + int max = 0; + int judge = 0; + int t; + for(t = 25; t < ppn;t++){ + + //printf("D%d\n",pp[t]); + + sp = pp[t]; + int g = sp % 10; + int s = (sp - g) % 100 / 10; + int b = (sp - 10 * s - g) / 100; + int sum = g + s + b; + int mul = g * s * b; + int mul2 = g * g + s * s + b * b; + + //printf("E%d %d %d %d \n",sp,g,s,b); + + judge = 0; + for(j = 0;j < ppn;j++){ + if(pp[j] == sum){ + judge++; + + //printf("Q1\n"); + + break; + } + } + + //printf("go\n"); + + for(j = 0;j < ppn;j++){ + if(pp[j] == mul){ + judge++; + + //printf("Q2\n"); + + break; + } + } + ; + for(j = 0;j < ppn;j++){ + if(pp[j] == mul2){ + judge++; + + //printf("Q3\n"); + + break; + } + } + + if(judge == 3){ + countsp++; + sumsp += sp; + max = sp; + + //printf("Q%d\n",sp); + + } + + } + printf("涓暟锛%d 鍜岋細%d 鏈澶э細%d \n",countsp,sumsp,max); + + return 0; } From 98987720f03a0ba8dd690ac99e1b7294e1ca4903 Mon Sep 17 00:00:00 2001 From: Time-wen <80614737+Time-wen@users.noreply.github.com> Date: Tue, 6 Apr 2021 10:32:28 +0800 Subject: [PATCH 06/12] homework1 --- SuperPrime_HW.cpp | 3 --- 1 file changed, 3 deletions(-) diff --git a/SuperPrime_HW.cpp b/SuperPrime_HW.cpp index f14dd768..f9ff9443 100644 --- a/SuperPrime_HW.cpp +++ b/SuperPrime_HW.cpp @@ -1,9 +1,6 @@ #include #include int main() { - #include -//sum <= 27 mul <= 729 mul2 <= 243 -int main(){ int p[1000] = {0}; int pp[1000] = {0}; int i = 2; From 906ff4bf52f90aec8c50561eca55267c26878835 Mon Sep 17 00:00:00 2001 From: Time_wen <1149699397@qq.com> Date: Tue, 13 Apr 2021 10:22:54 +0800 Subject: [PATCH 07/12] add test file --- amy/6.1.8.cpp | 87 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 87 insertions(+) create mode 100644 amy/6.1.8.cpp diff --git a/amy/6.1.8.cpp b/amy/6.1.8.cpp new file mode 100644 index 00000000..3d612895 --- /dev/null +++ b/amy/6.1.8.cpp @@ -0,0 +1,87 @@ +#include +#include +class Nature { +private: + const unsigned int num; +public: + Nature(int n):num(n){ + } + ~Nature(); + Nature add(Nature sp){ + return Nature(num + sp.num); + } + bool compare(Nature sp){ + if(num > sp.num) + return true; + return false; + } + bool isPrime(){ + for(int i = 2;i < num - 1;i++){ + if(num % i == 0){ + return false; + } + return true; + } + } + bool isSuperprime(){ + + } +}; + +class Superprime{ +private: + std::vector range; + +public: + Superprime(int a,int b){ + for(int i = a;i < b;i++){ + Nature nat(i); + if(nat.isSuperprime())//过滤器 只把 sp 放到容器里面 + range.push_back(nat); + } + } + ~Superprime(); + int max(){ + for(std::vector::iterator it = range.begin();it != range.end();it++){ + //想法是返回容器中最后一个元素(Nature型)的num。 + } + return 0; + } + int sum(){ + Nature sum1(0); + for(std::vector::iterator it = range.begin();it != range.end();it++){ + //想法是返回sum1中的sum() 的结果。 + } + return 0; + } + int howmany(){ + return range.size(); + } + +private: + void split(int x){ + int a,sum = 0,mult = 0 ,sqrsum = 0; + //分解每个位 + while(x != 0){ + a = x % 10; + sum += a; + mult *= a; + sqrsum += a * a; + x = x / 10; + } + } +}; + + + + +int main(){ + Superprime sp(100,999); + std::cout<< "max:"<< sp.max() << std::endl; + std::cout << "sum:" << sp.sum() << std::endl; + std::cout << "many:" << sp.howmany() < Date: Sun, 25 Apr 2021 14:12:52 +0800 Subject: [PATCH 08/12] update name --- SuperPrime_HW2.my.cpp | 151 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 151 insertions(+) create mode 100644 SuperPrime_HW2.my.cpp diff --git a/SuperPrime_HW2.my.cpp b/SuperPrime_HW2.my.cpp new file mode 100644 index 00000000..a9da1f27 --- /dev/null +++ b/SuperPrime_HW2.my.cpp @@ -0,0 +1,151 @@ +#include +#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 isSuperPrime(){ + int p[1000] = {0}; + int pp[1000] = {0}; + int i = 2; + for(;i < 1000;i++){//绛涙暟娉 + p[i] = i; + } + + int j = 0; + i = 2; + for(; i < 1000;i++){//鐢熸垚涓涓函鍑鐨勭礌鏁版暟缁 + if(p[i] == 0){ + continue; + } + pp[j] = p[i]; + + //printf("A%d %d\n",pp[j],j); + + j++; + int k = 2; + for(;(i * k) < 1000;k++){ + p[i * k] = 0; + } + } + + int ppn = j; + int countsp = 0; + int sumsp = 0; + int max = 0; + int judge = 0; + int t; + for(t = 25; t < ppn;t++){ + num = pp[t]; + int g = num % 10; + int s = (num - g) % 100 / 10; + int b = (num - 10 * s - g) / 100; + int sum = g + s + b; + int mul = g * s * b; + int mul2 = g * g + s * s + b * b; + + //printf("E%d %d %d %d \n",sp,g,s,b); + + judge = 0; + for(j = 0;j < ppn;j++){ + if(pp[j] == sum){ + judge++; + + //printf("Q1\n"); + + break; + } + } + + //printf("go\n"); + + for(j = 0;j < ppn;j++){ + if(pp[j] == mul){ + judge++; + + //printf("Q2\n"); + + break; + } + } + ; + for(j = 0;j < ppn;j++){ + if(pp[j] == mul2){ + judge++; + + //printf("Q3\n"); + + break; + } + } + + if(judge == 3){ + return true; + } + return false; + } +} + bool compare(Nature a){ + if(num < a.num){ + return true; + } + return false; + } + int show(){ + std::cout<< "max:"<< num < 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::iterator 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(100, 999); + Nature n = sp.max(); + //std::cout << "max:"<< ; + //the three numbers,howmany are they,the max of them. + n.show();//the max of them + + return 0; +} From 04a5e9971ccc2e7f15409072069fc18ea9ae7b28 Mon Sep 17 00:00:00 2001 From: Time_wen <1149699397@qq.com> Date: Sun, 25 Apr 2021 14:35:28 +0800 Subject: [PATCH 09/12] homework.f --- SuperPrime_HW2.cpp | 151 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 151 insertions(+) create mode 100644 SuperPrime_HW2.cpp diff --git a/SuperPrime_HW2.cpp b/SuperPrime_HW2.cpp new file mode 100644 index 00000000..a9da1f27 --- /dev/null +++ b/SuperPrime_HW2.cpp @@ -0,0 +1,151 @@ +#include +#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 isSuperPrime(){ + int p[1000] = {0}; + int pp[1000] = {0}; + int i = 2; + for(;i < 1000;i++){//绛涙暟娉 + p[i] = i; + } + + int j = 0; + i = 2; + for(; i < 1000;i++){//鐢熸垚涓涓函鍑鐨勭礌鏁版暟缁 + if(p[i] == 0){ + continue; + } + pp[j] = p[i]; + + //printf("A%d %d\n",pp[j],j); + + j++; + int k = 2; + for(;(i * k) < 1000;k++){ + p[i * k] = 0; + } + } + + int ppn = j; + int countsp = 0; + int sumsp = 0; + int max = 0; + int judge = 0; + int t; + for(t = 25; t < ppn;t++){ + num = pp[t]; + int g = num % 10; + int s = (num - g) % 100 / 10; + int b = (num - 10 * s - g) / 100; + int sum = g + s + b; + int mul = g * s * b; + int mul2 = g * g + s * s + b * b; + + //printf("E%d %d %d %d \n",sp,g,s,b); + + judge = 0; + for(j = 0;j < ppn;j++){ + if(pp[j] == sum){ + judge++; + + //printf("Q1\n"); + + break; + } + } + + //printf("go\n"); + + for(j = 0;j < ppn;j++){ + if(pp[j] == mul){ + judge++; + + //printf("Q2\n"); + + break; + } + } + ; + for(j = 0;j < ppn;j++){ + if(pp[j] == mul2){ + judge++; + + //printf("Q3\n"); + + break; + } + } + + if(judge == 3){ + return true; + } + return false; + } +} + bool compare(Nature a){ + if(num < a.num){ + return true; + } + return false; + } + int show(){ + std::cout<< "max:"<< num < 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::iterator 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(100, 999); + Nature n = sp.max(); + //std::cout << "max:"<< ; + //the three numbers,howmany are they,the max of them. + n.show();//the max of them + + return 0; +} From bf6548f45c015b0af9d0c610820fcd2bbc27c40f Mon Sep 17 00:00:00 2001 From: Time-wen <80614737+Time-wen@users.noreply.github.com> Date: Sun, 25 Apr 2021 15:22:04 +0800 Subject: [PATCH 10/12] Delete SuperPrime_HW2.cpp --- SuperPrime_HW2.cpp | 151 --------------------------------------------- 1 file changed, 151 deletions(-) delete mode 100644 SuperPrime_HW2.cpp diff --git a/SuperPrime_HW2.cpp b/SuperPrime_HW2.cpp deleted file mode 100644 index a9da1f27..00000000 --- a/SuperPrime_HW2.cpp +++ /dev/null @@ -1,151 +0,0 @@ -#include -#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 isSuperPrime(){ - int p[1000] = {0}; - int pp[1000] = {0}; - int i = 2; - for(;i < 1000;i++){//绛涙暟娉 - p[i] = i; - } - - int j = 0; - i = 2; - for(; i < 1000;i++){//鐢熸垚涓涓函鍑鐨勭礌鏁版暟缁 - if(p[i] == 0){ - continue; - } - pp[j] = p[i]; - - //printf("A%d %d\n",pp[j],j); - - j++; - int k = 2; - for(;(i * k) < 1000;k++){ - p[i * k] = 0; - } - } - - int ppn = j; - int countsp = 0; - int sumsp = 0; - int max = 0; - int judge = 0; - int t; - for(t = 25; t < ppn;t++){ - num = pp[t]; - int g = num % 10; - int s = (num - g) % 100 / 10; - int b = (num - 10 * s - g) / 100; - int sum = g + s + b; - int mul = g * s * b; - int mul2 = g * g + s * s + b * b; - - //printf("E%d %d %d %d \n",sp,g,s,b); - - judge = 0; - for(j = 0;j < ppn;j++){ - if(pp[j] == sum){ - judge++; - - //printf("Q1\n"); - - break; - } - } - - //printf("go\n"); - - for(j = 0;j < ppn;j++){ - if(pp[j] == mul){ - judge++; - - //printf("Q2\n"); - - break; - } - } - ; - for(j = 0;j < ppn;j++){ - if(pp[j] == mul2){ - judge++; - - //printf("Q3\n"); - - break; - } - } - - if(judge == 3){ - return true; - } - return false; - } -} - bool compare(Nature a){ - if(num < a.num){ - return true; - } - return false; - } - int show(){ - std::cout<< "max:"<< num < 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::iterator 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(100, 999); - Nature n = sp.max(); - //std::cout << "max:"<< ; - //the three numbers,howmany are they,the max of them. - n.show();//the max of them - - return 0; -} From a71edee2aae7bd93c146e52fd399bda95500ce0c Mon Sep 17 00:00:00 2001 From: Time-wen <80614737+Time-wen@users.noreply.github.com> Date: Sun, 25 Apr 2021 15:22:21 +0800 Subject: [PATCH 11/12] Delete SuperPrime_HW2.my.cpp --- SuperPrime_HW2.my.cpp | 151 ------------------------------------------ 1 file changed, 151 deletions(-) delete mode 100644 SuperPrime_HW2.my.cpp diff --git a/SuperPrime_HW2.my.cpp b/SuperPrime_HW2.my.cpp deleted file mode 100644 index a9da1f27..00000000 --- a/SuperPrime_HW2.my.cpp +++ /dev/null @@ -1,151 +0,0 @@ -#include -#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 isSuperPrime(){ - int p[1000] = {0}; - int pp[1000] = {0}; - int i = 2; - for(;i < 1000;i++){//绛涙暟娉 - p[i] = i; - } - - int j = 0; - i = 2; - for(; i < 1000;i++){//鐢熸垚涓涓函鍑鐨勭礌鏁版暟缁 - if(p[i] == 0){ - continue; - } - pp[j] = p[i]; - - //printf("A%d %d\n",pp[j],j); - - j++; - int k = 2; - for(;(i * k) < 1000;k++){ - p[i * k] = 0; - } - } - - int ppn = j; - int countsp = 0; - int sumsp = 0; - int max = 0; - int judge = 0; - int t; - for(t = 25; t < ppn;t++){ - num = pp[t]; - int g = num % 10; - int s = (num - g) % 100 / 10; - int b = (num - 10 * s - g) / 100; - int sum = g + s + b; - int mul = g * s * b; - int mul2 = g * g + s * s + b * b; - - //printf("E%d %d %d %d \n",sp,g,s,b); - - judge = 0; - for(j = 0;j < ppn;j++){ - if(pp[j] == sum){ - judge++; - - //printf("Q1\n"); - - break; - } - } - - //printf("go\n"); - - for(j = 0;j < ppn;j++){ - if(pp[j] == mul){ - judge++; - - //printf("Q2\n"); - - break; - } - } - ; - for(j = 0;j < ppn;j++){ - if(pp[j] == mul2){ - judge++; - - //printf("Q3\n"); - - break; - } - } - - if(judge == 3){ - return true; - } - return false; - } -} - bool compare(Nature a){ - if(num < a.num){ - return true; - } - return false; - } - int show(){ - std::cout<< "max:"<< num < 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::iterator 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(100, 999); - Nature n = sp.max(); - //std::cout << "max:"<< ; - //the three numbers,howmany are they,the max of them. - n.show();//the max of them - - return 0; -} From 9b748eba7df900e338b6e94b5dbec0729c253410 Mon Sep 17 00:00:00 2001 From: Time_wen <1149699397@qq.com> Date: Sun, 25 Apr 2021 15:38:30 +0800 Subject: [PATCH 12/12] homework again --- SuperPrime_HW2.cpp | 179 ++++++++++++++++++++++++++++++--------------- 1 file changed, 118 insertions(+), 61 deletions(-) diff --git a/SuperPrime_HW2.cpp b/SuperPrime_HW2.cpp index ec1c77f3..a9da1f27 100644 --- a/SuperPrime_HW2.cpp +++ b/SuperPrime_HW2.cpp @@ -1,94 +1,151 @@ #include #include +#include class Nature { private: int num; public: Nature():num(0){ - std::cout << "Default Create Nature as " << num << std::endl; + //std::cout << "Default Create Nature as " << num << std::endl; } Nature(int n):num(n) { - std::cout << "Create Nature as " << num << std::endl; + //std::cout << "Create Nature as " << num << std::endl; } Nature(const Nature &nat):num(nat.num){ - std::cout << "Copy Create Nature as " << num << std::endl; + //std::cout << "Copy Create Nature as " << num << std::endl; } ~Nature() { - std::cout << "Destroy Nature as " << num << std::endl; + //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; + bool isSuperPrime(){ + int p[1000] = {0}; + int pp[1000] = {0}; + int i = 2; + for(;i < 1000;i++){//绛涙暟娉 + p[i] = i; + } + + int j = 0; + i = 2; + for(; i < 1000;i++){//鐢熸垚涓涓函鍑鐨勭礌鏁版暟缁 + if(p[i] == 0){ + continue; + } + pp[j] = p[i]; + + //printf("A%d %d\n",pp[j],j); + + j++; + int k = 2; + for(;(i * k) < 1000;k++){ + p[i * k] = 0; + } + } + + int ppn = j; + int countsp = 0; + int sumsp = 0; + int max = 0; + int judge = 0; + int t; + for(t = 25; t < ppn;t++){ + num = pp[t]; + int g = num % 10; + int s = (num - g) % 100 / 10; + int b = (num - 10 * s - g) / 100; + int sum = g + s + b; + int mul = g * s * b; + int mul2 = g * g + s * s + b * b; + + //printf("E%d %d %d %d \n",sp,g,s,b); + + judge = 0; + for(j = 0;j < ppn;j++){ + if(pp[j] == sum){ + judge++; + + //printf("Q1\n"); + + break; + } + } + + //printf("go\n"); + + for(j = 0;j < ppn;j++){ + if(pp[j] == mul){ + judge++; + + //printf("Q2\n"); + + break; + } + } + ; + for(j = 0;j < ppn;j++){ + if(pp[j] == mul2){ + judge++; + + //printf("Q3\n"); + + break; + } + } + + if(judge == 3){ + return true; + } + return false; } - int compare(const Nature &nat) { - if (num > nat.num) - return 1; - else if(num == nat.num) - return 0; - - return -1; +} + bool compare(Nature a){ + if(num < a.num){ + return true; + } + return false; } -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; + int show(){ + std::cout<< "max:"<< num < natures; + std::vector natures; public: - Container(int a, int b) { - std::cout << "Create SuperPrime from " << a << " to " << b << std::endl; + SuperPrime(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; + Nature nat(i); + //std::cout << "HAHA" << std::endl; + natures.push_back(nat); + //std::cout << "DDDDD" << std::endl; } } - ~Container() { - std::cout << "Destroy SuperPrime " << std::endl; + ~SuperPrime() { + //std::cout << "Destroy SuperPrime " << std::endl; } - SuperPrime max() { - std::vector::iterate it = natures.begin(); + Nature max() { + std::vector::iterator it = natures.begin(); Nature max(0); - for(; it != natures.end(); it ++) { - if (max.compare(*it)) { + for(; it != natures.end(); it++) { + if(it->isSuperPrime()) { + + if (max.compare(*it)) { max = *it; - } + } + } } return max; } + }; -int main() { - SuperPrime sp(10, 13); +int main(){ + SuperPrime sp(100, 999); Nature n = sp.max(); - std::cout << "锟斤拷蟪锟斤拷锟斤拷锟斤拷锟" ; - n.show(); - + //std::cout << "max:"<< ; + //the three numbers,howmany are they,the max of them. + n.show();//the max of them + return 0; -} +}