-
Notifications
You must be signed in to change notification settings - Fork 78
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
base: master
Are you sure you want to change the base?
all #49
Changes from 6 commits
43f9ea3
b7ef4ea
d9a4680
b6045c4
6669157
0435043
ef4660b
2934f29
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
//Refer:https://blog.csdn.net/pilifeng1/article/details/82814997 | ||
//https://baike.baidu.com/item/%E6%A2%85%E9%92%A6%E5%85%AC%E5%BC%8F/9425108? | ||
#include <cstdio> | ||
#define MAX_RANGE /*(2 << 29 - 1)*/ 100000 | ||
double arccot(int n,int digit)//所以要怎么控制迭代经度呢?如果用浮点数就会产生问题 | ||
{ | ||
for() | ||
} | ||
int main() | ||
{ | ||
double PI; | ||
PI=4*(4*arccot(5)-arccot(239)); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
0 0 0 5 5 5 0 0 0 0 0 0 0 0 0 0 0 0 0 0 | ||
0 0 0 5 2 5 0 0 0 0 0 0 0 0 0 0 0 0 0 0 | ||
5 5 5 5 0 5 0 0 0 0 0 0 0 0 0 0 0 0 0 0 | ||
5 2 3 0 3 5 5 5 0 0 0 0 0 0 0 0 0 0 0 0 | ||
5 5 5 1 3 0 2 5 0 0 0 0 0 0 0 0 0 0 0 0 | ||
0 0 5 3 5 5 5 5 0 0 0 0 0 0 0 0 0 0 0 0 | ||
0 0 5 2 5 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 | ||
0 0 5 5 5 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 | ||
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 | ||
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 | ||
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 | ||
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 | ||
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 | ||
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 | ||
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 | ||
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 | ||
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 | ||
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 | ||
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 | ||
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 |
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; | ||
} |
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); | ||
} | ||
} | ||
} |
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); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#include <stdio.h> | ||
void get_threeDigit_Number(const int targetnumber,int *digit_number) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 下划线风格或驼峰风格,用一种就好吧;当然全大写的常量用下划线分割一下不错 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 好的,明白了,谢谢俸爷,以后会注意的 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 不用以后注意了,这次就改掉吧 |
||
{ | ||
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; | ||
} |
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); | ||
} | ||
} |
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."); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
#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; i++, p++, w++) | ||
{ | ||
p->weight = *w; | ||
p->lchild = -1; | ||
p->rchild = -1; | ||
p->parent = -1; | ||
} | ||
|
||
for (; i < m; i++, p++) | ||
{ | ||
p->weight = 0; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 有重复的味道,请消除之 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 这里不是重复,是哈夫曼树的初始化,因为变量p和w申明在前面的,所以前面初始化后,后面的指针还可以再用 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 我不是指功能重复了,而是指代码重复了;建议看看Martin Fowler的《重构》 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 好,这里我真没理解俸爷的意思,我去看下这本书然后考虑下怎么改掉这里。 |
||
p->lchild = -1; | ||
p->rchild = -1; | ||
p->parent = -1; | ||
} | ||
//构造HUFFMAN TREE | ||
for (i = n; i < m; i++) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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;//记录根节点位置 | ||
} | ||
} |
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); |
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. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
还没实现完成吧? 如果是没完成的代码,就不要commit,更不要push了
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
没有,完成的会弄在level2的文件夹里面,这个course-c文件夹只是暂存。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
我的锅,下次把这个文件夹给删除了。。。