diff --git a/SuperPrime-HW2.cpp b/SuperPrime-HW2.cpp index 9f16866e..03954f6b 100644 --- a/SuperPrime-HW2.cpp +++ b/SuperPrime-HW2.cpp @@ -1,5 +1,6 @@ #include #include +#include class Nature { private: int num; @@ -16,41 +17,89 @@ class Nature { ~Nature() { std::cout << "Destroy Nature as " << num << std::endl; } + void show(){ + + } + 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 { +class SuperPrime : public Nature { +private: + int num; +public: + int max(){ + + } + SuperPrime(int n,int b) { + + } + + SuperPrime(int n):num(n) { + } + bool isSuperPrime() { + Nature nat(num); + return nat.isPrime(); + } + 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: - 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() { - std::cout << "Destroy SuperPrime " << std::endl; - } - Nature max() { - std::vector::iterate it = natures.begin(); + SuperPrime max() { + std::vector::iterator 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; + return 0; } }; int main() { SuperPrime sp(10, 13); Nature n = sp.max(); - std::cout << "��󳬼�������" ; + std::cout << "・ス・スャシ・ス・ス・ス・ス・ス・ス・ス" ; n.show(); return 0; diff --git a/SuperPrime_HW.cpp b/SuperPrime_HW.cpp index 0e004b50..ed4bc079 100644 --- a/SuperPrime_HW.cpp +++ b/SuperPrime_HW.cpp @@ -1,5 +1,58 @@ -#include +#include +#include +#include + +int main(){ + + int i,n,num=0,max=0; + int jia=0; + for(i=101;i<1000;i=i+2){ + + int count=0; + char a[5]; + n=i; + a[0]=n%10; + a[1]=n/10%10; + a[2]=n/100; + + + int sum,mul,u; + sum=a[0]+a[1]+a[2]; + mul=a[0]*a[2]*a[1]; + u=a[0]*a[0]+a[1]*a[1]+a[2]*a[2]; + + for(int y=2;y<=sqrt(i);y++){ + if(i%y==0) count++; + } + for(int y=2;y<=sqrt(sum);y++){ + if(sum%y==0) count++; + } + + if(mul!=0 && mul!=1){ + for(int y=2;y +#include + +class Nature{ + private: + int num; + int a,b,c; + int add,x,sqrtsum; + + public: + Nature(int num); + int sum(int a,int b,int c); + int mul(int a,int b,int c); + int sqrts(int a,int b,int c); + +}; + + Nature::Nature(int num){ + a=num%10; + b=num/10%10; + c=num/100; + } + + Nature::sum(int a,int b,int c){ + add=a+b+c; + } + + Nature::mul(int a,int b,int c){ + x=a*b*c; + } + + Nature::sqrts(int a,int b,int c){ + sqrtsum=a*a+b*b+c*c; + } + + +class SuperPrime{ + private: + int i; + + public: + Nature sp(int i); + SuperPrime(int i,int sum,int mul ,int sqrts); + int max(int i); + int he(int i); +}; + + SuperPrime::SuperPrime(int i,int sum,int mul ,int sqrts){ + int count=0; + for(int h=2;h +#include + +int main(){ + + int i,n,num=0,max=0; + int jia=0; + for(i=101;i<1000;i=i+2){ + + int count=0; + char a[5]; + n=i; + a[0]=n%10; + a[1]=n/10%10; + a[2]=n/100; + + + int sum,mul,u; + sum=a[0]+a[1]+a[2]; + mul=a[0]*a[2]*a[1]; + u=a[0]*a[0]+a[1]*a[1]+a[2]*a[2]; + + for(int y=2;y<=sqrt(i);y++){ + if(i%y==0) count++; + } + for(int y=2;y<=sqrt(sum);y++){ + if(sum%y==0) count++; + } + + if(mul!=0 && mul!=1){ + for(int y=2;y