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

all #49

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open

all #49

Show file tree
Hide file tree
Changes from all commits
Commits
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
Empty file modified C语言学习笔记.md
100755 → 100644
Empty file.
Empty file modified README.md
100755 → 100644
Empty file.
Empty file modified level0/README.md
100755 → 100644
Empty file.
Empty file modified level0/bubbleSort/README.md
100755 → 100644
Empty file.
Empty file modified level1/p01_runningLetter/README.md
100755 → 100644
Empty file.
45 changes: 45 additions & 0 deletions level1/p01_runningLetter/runningLetter.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#include <stdio.h>
#include <stdlib.h>
#include <Windows.h>
#define SCREENLENGTH 10
#define SLEEPTIME 300 //if you can't see the letter move,please modify this number.
void PrintSpace(int n) //enter the amount of space.
{
for (int i = 0; i < n; i++)
{
printf(" ");
}
}
int main()
{
while (1)
{
int j = 0;
int TempForDection = 0;
while (j >= 0 && j <= SCREENLENGTH) //Condition is very clear.
{

PrintSpace(j);
printf("S");
if (TempForDection == 0)
{
j++;
}
if (TempForDection == 1)
{
j--;
}
if (j == SCREENLENGTH)
{
TempForDection = 1;
}
if (j == 0)
{
TempForDection = 0;
}
Sleep(SLEEPTIME);
system("cls");
}
}
return 0;
}
Empty file modified level1/p02_isPrime/README.md
100755 → 100644
Empty file.
38 changes: 38 additions & 0 deletions level1/p02_isPrime/is_Prime.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#include <stdio.h>
#define MAX_RANGE /*(2 << 29 - 1)*/ 100000
int main()
{
int n;
int funCode = 1; //zero is allPrimes,one is isPrime
while (scanf("%d", &n) == 1 && n > 1)
{
int A[MAX_RANGE] = {0}; //Use zero to represent this is a prime.Use one to represent this is a prime.
int num = 0;
int TempOfPrime[MAX_RANGE];
for (int i = 2; i <= n; i++)
{
if (!A[i])
{
num += 1;
TempOfPrime[num] = i; //Attention:First element is a[1]
}
for (int j = 1; j <= num&&i*TempOfPrime[j]<=n; j++)
{
A[i * TempOfPrime[j]] = 1;
if ((i % TempOfPrime[j])==0)
break;
}
}
if (!funCode)
{
for (int i = 2; i <= n; i++)
if (!A[i])
printf("%d ", i);
}
else
{

(!A[n]) ? printf("%d is prime ", n) : printf("%d is not prime ", n);
}
}
}
Empty file modified level1/p03_Diophantus/README.md
100755 → 100644
Empty file.
9 changes: 9 additions & 0 deletions level1/p03_Diophantus/diu.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#include <stdio.h>
int main()
{
int i=0;
for(;i<100;i++)
if((1*12*7/6*i+1*12*7/12*i+1*12*7/7*i+5*12*7+1*12*7/2*i+4*12*7)==i*12*7)
break;
printf("His age is :%d",i);
}
Empty file modified level1/p04_ narcissus/README.md
100755 → 100644
Empty file.
28 changes: 28 additions & 0 deletions level1/p04_ narcissus/narcissus.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#include <stdio.h>
void getThreeDigitNumber(const int targetnumber,int *digit_number)
{
int i=targetnumber;
int j=0;
while(i)
{
digit_number[j++]=i%10;
i/=10;
}
}
int main()
{
int digit_number[3];
for(int i=100;i<1000;i++)
{
int sum=0;
get_threeDigit_Number(i,digit_number);
for(int j=0;j<3;j++)
{
sum+=digit_number[j]*digit_number[j]*digit_number[j];
}
if(sum==i){
printf("%d ",i);
}
}
return 0;
}
Empty file modified level1/p05_allPrimes/README.md
100755 → 100644
Empty file.
43 changes: 43 additions & 0 deletions level1/p05_allPrimes/is_Prime.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#include <stdio.h>
#define MAX_RANGE /*(2 << 29 - 1)*/ 100000
#include <time.h>
int main()
{
clock_t t1 = clock();
int n;
int funCode = 0; //zero is allPrimes,one is isPrime
while (scanf("%d", &n) == 1 && n > 1)
{
int A[MAX_RANGE] = {0}; //Use zero to represent this is a prime.Use one to represent this is a prime.
int num = 0;
int TempOfPrime[MAX_RANGE];
for (int i = 2; i <= n; i++)
{
if (!A[i])
{
num += 1;
TempOfPrime[num] = i; //Attention:First element is a[1]
}
for (int j = 1; j <= num&&i*TempOfPrime[j]<=n; j++)
{
A[i * TempOfPrime[j]] = 1;
if ((i % TempOfPrime[j])==0)
break;
}
}

if (!funCode)
{
for (int i = 2; i <= n; i++)
if (!A[i])
printf("%d ", i);
}
else
{

(!A[n]) ? printf("%d is prime ", n) : printf("%d is not prime ", n);
}
clock_t t2 = clock();
printf("Execution time is: %fs\n", double(t2-t1)/CLOCKS_PER_SEC);
}
}
53 changes: 53 additions & 0 deletions level1/p06_Goldbach/Goldbach.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#include <cstdio>
#include <set>
#define MAX_RANGE /*(2 << 29 - 1)*/ 100000
using namespace std;
int main()
{
const int n=101;//The range of number you want to prove
set<int> storage_Prime;

int A[MAX_RANGE] = {0}; //Use zero to represent this is a prime.Use one to represent this is a prime.
int num = 0;
//generate Prime
int TempOfPrime[MAX_RANGE];
for (int i = 2; i <= n; i++)
{
if (!A[i])
{
num += 1;
TempOfPrime[num] = i; //Attention:First element is a[1]
}
for (int j = 1; j <= num && i * TempOfPrime[j] <= n; j++)
{
A[i * TempOfPrime[j]] = 1;
if ((i % TempOfPrime[j]) == 0)
break;
}
for (int i = 2; i <= n; i++)
{
if (!A[i])
{
storage_Prime.insert(i);
}
}
}
for(int i=4;i<n;i+=2)
{
int flag=1;//有问题
for(set<int>::const_iterator citer=storage_Prime.begin();(*citer)<=i&&citer!=storage_Prime.end();citer++)
{
int remainder=i-*citer;
if(storage_Prime.find(remainder) != storage_Prime.end())//If find in Prime Set
{
flag=0;//
}
}
if(flag)
{
printf("Goldbach is not right.");
return 0;
}
}
printf("Goldbach is right.");
}
Empty file modified level1/p06_Goldbach/README.md
100755 → 100644
Empty file.
66 changes: 66 additions & 0 deletions level1/p07_encrypt_decrypt/Huffman.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
#include "pch.h"
#include "Huffman.h"
void HuffmanCoding(HNode *HT, HCode *HC, unsigned long long *w, const int n)
{
//初始化
int m = 2 * n - 1;
HNode *p = HT;
int i = 0;
//听取俸爷建议,重构此处代码
for (; i < n+m; i++, p++)
{
if (i >= n)
{
p->weight = 0;
}
else
{
p->weight = *w;
w++;
}
p->lchild = -1;
p->rchild = -1;
p->parent = -1;
}
//构造HUFFMAN TREE
for (i = n; i < m; i++)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

与其写一个注释来说明,不如提取为一个函数,再给它个好名字

{
long long min1 = MAXVALUE, min2 = MAXVALUE;
int min1id = 0, min2id = 0; //min1是最小的,min2次小
for (int j = 0; j < i; j++)
{
if (HT[j].parent == -1 && HT[j].weight < min1)
{
min2 = min1;
min2id = min1id;
min1 = HT[j].weight;
min1id = j;
}
else if (HT[j].parent == -1 && HT[j].weight < min2)
{
min2 = HT[j].weight;
min2id = j;
}
}
HT[min1id].parent = i;
HT[min2id].parent = i;
HT[i].lchild = min1id;
HT[i].rchild = min2id;
HT[i].weight = min1 + min2;
}
//做字符编码
for (int j = 0; j < n; j++)
{
int start = n - 1;
for (int tempid = j, tempparent = HT[j].parent; tempparent != -1; tempid = tempparent, tempparent = HT[tempparent].parent)
{
if (HT[tempparent].lchild == tempid)
{
HC[j].bit[start--] = 0;
}
else
HC[j].bit[start--] = 1;
}
HC[j].start = start + 1; //记录根节点位置
}
}
14 changes: 14 additions & 0 deletions level1/p07_encrypt_decrypt/Huffman.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#pragma once
#define MAXBIT 256
const long long MAXVALUE = 9223372036854775806;
typedef struct HNode {
long long weight;
int parent;
int lchild;
int rchild;
} HNode;
typedef struct HCode {
int bit[MAXBIT];
int start;
} HCode;
void HuffmanCoding(HNode *HT, HCode *HC, unsigned long long *w, const int n);
7 changes: 6 additions & 1 deletion level1/p07_encrypt_decrypt/README.md
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
### 功能要求:

1. 分别编写“加密”、“解密”函数,输入为任意长度的字符串
<<<<<<< HEAD
1. 分别编写“加密”、“解密”函数,输入为任意长度的字符串


MY program:Huffman encoding.This program can deal with any format below 4GB.

Loading