Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

superprime #136

Open
wants to merge 39 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
1af858f
Add files via upload
chendansunshine Mar 29, 2021
93879d4
陈丹 2020141460258 超级素数C语言
chendansunshine Mar 30, 2021
f184d42
Add files via upload
chendansunshine Apr 5, 2021
029da40
Add files via upload
chendansunshine Apr 5, 2021
8dff566
Add files via upload
chendansunshine Apr 13, 2021
c2a31e2
Add files via upload
chendansunshine Apr 13, 2021
ace2019
Add files via upload
chendansunshine Apr 13, 2021
e3ca85e
Super Prime
chendansunshine Apr 13, 2021
a88d335
Superprime
chendansunshine Apr 13, 2021
2766ebc
Add files via upload
chendansunshine Apr 13, 2021
1ddba6f
Super Prime
chendansunshine Apr 13, 2021
b767132
homework
chendansunshine Apr 13, 2021
15ace61
Add files via upload
chendansunshine Apr 13, 2021
a725182
Add files via upload
chendansunshine Apr 13, 2021
e4f3d33
Add files via upload
chendansunshine Apr 13, 2021
8c891ef
homework
chendansunshine Apr 13, 2021
738fe83
superprime
chendansunshine Apr 13, 2021
c6b0012
Add files via upload
chendansunshine Apr 13, 2021
b919e7c
Add files via upload
chendansunshine Apr 20, 2021
42e2a91
update
chendansunshine Apr 20, 2021
38b35ea
update
chendansunshine Apr 20, 2021
279cc52
SuperPrime_HW2cccc.cpp
chendansunshine Apr 25, 2021
6675a92
SuperPrime_HW2cccc.cpp
chendansunshine Apr 25, 2021
84882a3
SuperPrime_HW2cccc.cpp
chendansunshine Apr 25, 2021
ef2cef6
SuperPrime_HW2cccc.cpp
chendansunshine Apr 25, 2021
96bda50
SuperPrime_HW2.cpp
chendansunshine Apr 25, 2021
03ce38b
Delete SuperPrime_HW2cccc.cpp
chendansunshine Apr 25, 2021
fb45736
Delete main.cpp
chendansunshine Apr 25, 2021
7c79f11
Delete SuperPrime_HW.cpp
chendansunshine Apr 25, 2021
de83e5b
Delete SuperPrime2.cpp
chendansunshine Apr 25, 2021
9d4ea04
Delete SuperPrime.cpp
chendansunshine Apr 25, 2021
700c463
Delete Makefile
chendansunshine Apr 25, 2021
b5f10ae
Makefile
chendansunshine Apr 25, 2021
712b873
SuperPrime.cpp
chendansunshine Apr 25, 2021
6a31964
SuperPrime2.cpp
chendansunshine Apr 25, 2021
acb70ad
SuperPrime_HW.cpp
chendansunshine Apr 25, 2021
5254a6b
main.cpp
chendansunshine Apr 25, 2021
1df7146
SuperPrime_HW2.cpp
chendansunshine Apr 25, 2021
206e0de
SuperPrime_HW2.cpp
chendansunshine Apr 25, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions .github/workflows/c-cpp.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: C/C++ CI

on:
push:
branches: [ master ]
pull_request:
branches: [ master ]

jobs:
build:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- name: cppcheck-action
uses: deep5050/[email protected]
- name: make
run: make
- name: make check
run: make check
- name: make distcheck
run: make distcheck
13 changes: 13 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
all: main sp

main:main.cpp
$(CXX) main.cpp -o main

sp:SuperPrime_HW.cpp
$(CXX) SuperPrime_HW.cpp -o sp
$(CXX) SuperPrime_HW2.cpp -o sp

check:


distcheck:
114 changes: 45 additions & 69 deletions SuperPrime.cpp
Original file line number Diff line number Diff line change
@@ -1,81 +1,57 @@
class Number {
#include <iostream>
#include <vector>
class Nature {
private:
int num;
public:
Number(int num):mNum(num) {
Nature():num(0){
std::cout << "Default Create Nature as " << num << std::endl;
}
Number(const Number &n):mNum(n.mNum) {
Nature(int n):num(n) {
std::cout << "Create Nature as " << num << std::endl;
}
~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;
Nature(const Nature &nat):num(nat.num){
std::cout << "Copy Create Nature as " << num << std::endl;
}
bool isPrime() {
for(int i = 2; i < mNum; ++i) {
if(mNum % i == 0)
break;
}
if(i != mNum)
return false;
return true;
~Nature() {
std::cout << "Destroy Nature as " << num << std::endl;
}
private:
const int mNum;
};
class NumberSet {
class SuperPrime {
private:
Number *nums[20];
int size;
std::vector<Nature> natures;
public:
NumberSet() {
size = 0;
for(int i = 0; i < 20; ++i)
nums[i] = NULL;
}
~NumberSet() {
for(int i = 0; i < size; ++i)
delete nums[i];
}
bool add(const Number &n) {
if(size != 20 && nums[size] == NULL) {
nums[size] = new Number(n);
size += 1;
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);
std::cout << "HAHA" << std::endl;
natures.push_back(nat);
std::cout << "DDDDD" << std::endl;
}
}
Number sum() {
Number sum(0);
for(int i = 0; i < size; ++i) {
if(nums[i] != NULL)
sum.add(*(nums[i]));
~SuperPrime() {
std::cout << "Destroy SuperPrime " << std::endl;
}

Nature max() {
std::vector<Nature>::iterate it = natures.begin();
Nature max(0);
for(; it != natures.end(); it ++) {
if(it->isSuperPrime()) {
if (max.compare(*it)) {
max = *it;
}
}
}
return sum;
return max;
}
};
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() {
SuperPrime sp(10, 13);
Nature n = sp.max();
std::cout << "��󳬼�������" ;
n.show();

return 0;
}
180 changes: 61 additions & 119 deletions SuperPrime2.cpp
Original file line number Diff line number Diff line change
@@ -1,124 +1,66 @@
//��ҵ���������������¿�ܵĴ���ϸ�ڣ������ܱ������еõ���ȷ���
#include <iostream>
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;
#include <vector>
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 {
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:
std::vector<Nature> range; //��������������
public:
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(std::vector<Nature>::iterate it = range.begin();
it != range.end(); it++) {
if(it->compare())
}
return 0;
}

int howmany() {
return range.size();
}
int sum() {
for(std::vector<Nature>::iterate it = range.begin();
it != range.end(); it++) {
}
}
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;
}
}
};
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 << "���ij���������" << sp.max() << std::endl;
std::cout << "��������������" << sp.howmany() << std::endl;
std::cout << "���������ĺͣ�" << sp.sum() << std::endl;
return 0;
}
}
5 changes: 5 additions & 0 deletions SuperPrime_HW.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#include <iostream>

int main() {
return 0;
}
Loading