-
Notifications
You must be signed in to change notification settings - Fork 35
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
lvl1_1_to_8 #29
Open
Kyrios0
wants to merge
10
commits into
luckymark:master
Choose a base branch
from
Kyrios0:lvl1_1_to_8
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
lvl1_1_to_8 #29
Changes from 2 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
0191231
lvl1_1_to_8
Kyrios0 d750ed2
lvl1_9
Kyrios0 0636e35
微小的工作
Kyrios0 6603088
修修补补
Kyrios0 4d35a10
微小的工作
Kyrios0 a9f3a71
111
Kyrios0 c765dd0
170606
Kyrios0 f313a0a
170611
Kyrios0 fefbf4a
0614
Kyrios0 736465c
0623
Kyrios0 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
46 changes: 46 additions & 0 deletions
46
practices/c/level1/p01_runningLetter/lvl1_1_Running_letter.c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/* code: Running Letter | ||
* author: Kyrios0 | ||
* date: 2017.02.26 | ||
* state: finished | ||
* version: 1.0.0 | ||
*/ | ||
|
||
#include<stdio.h> | ||
#include<windows.h> | ||
|
||
void gotoxy(int x, int y) | ||
{ | ||
HANDLE hOutput; | ||
COORD coo; | ||
coo.X = x; | ||
coo.Y = y; | ||
hOutput = GetStdHandle(STD_OUTPUT_HANDLE); | ||
SetConsoleCursorPosition(hOutput, coo); | ||
} | ||
|
||
int main(int argc, char** argv) | ||
{ | ||
system("chcp 437"); | ||
system("color 0f"); | ||
system("mode con cols=63 lines=32"); | ||
|
||
int x = 0, y = 0, round = 0; | ||
|
||
while(1) | ||
{ | ||
system("cls"); | ||
|
||
gotoxy(x, y); | ||
putchar('#'); | ||
gotoxy(x, y); | ||
|
||
(round % 2 == 0) ? x++ : x--; | ||
if((x == 0) || (x == 63)) | ||
{ | ||
round++; | ||
} | ||
|
||
Sleep(25); | ||
} | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
// isPrime.cpp | ||
// | ||
|
||
#include "stdafx.h" | ||
/* code: Linked list Step0 for eratosthenes Prime (change from lvl1_5) | ||
* author: Kyrios0 | ||
* date: 2017.02.21 | ||
* state: finished | ||
* version: 1.0.2 | ||
*/ | ||
|
||
#include<stdio.h> | ||
#include<stdlib.h>//malloc() | ||
#include<string.h> | ||
#include<Windows.h> | ||
|
||
typedef struct linked { | ||
int data; | ||
linked *next; | ||
}linked; | ||
|
||
linked* creat(int length) | ||
{ | ||
linked *head, *tail, *p; | ||
int x; | ||
head = tail = NULL; | ||
|
||
for (x = 0; x < length; x++) | ||
{ | ||
p = (linked *)malloc(sizeof(linked)); | ||
p->data = x + 2;//0 and 1 aren't prime or composite number | ||
p->next = NULL; | ||
|
||
if (head == NULL) | ||
{ | ||
head = tail = p; | ||
} | ||
else | ||
{ | ||
tail = tail->next = p; | ||
} | ||
} | ||
|
||
return head; | ||
} | ||
|
||
int main(int argc, char** argv) | ||
{ | ||
long len, userNumber, finalNumber = 2; | ||
|
||
puts("Prime Number Detection System"); | ||
puts("Please enter the number you want to detect(It should be no less than 2)"); | ||
scanf("%ld", &userNumber); | ||
|
||
len = userNumber; | ||
linked *current, *head, *temp, *currenthead; | ||
current = creat(len); | ||
head = current; | ||
currenthead = head; | ||
|
||
puts("Working..."); | ||
|
||
for (long i = 0; ; i++) | ||
{ | ||
if (i * i >= len)//Termination | ||
{ | ||
break; | ||
} | ||
|
||
while (current->next != NULL) | ||
{ | ||
temp = current->next; | ||
|
||
while (temp->data % currenthead->data == 0)//Delete this number | ||
{ | ||
current->next = temp->next; | ||
temp = temp->next; | ||
len--; | ||
if (temp == NULL) | ||
{ | ||
break; | ||
} | ||
} | ||
|
||
if (current->next == NULL) | ||
{ | ||
break; | ||
} | ||
else | ||
{ | ||
current = current->next; | ||
} | ||
} | ||
|
||
finalNumber = current->data; | ||
currenthead = currenthead->next; | ||
current = currenthead; | ||
} | ||
|
||
printf(((finalNumber == userNumber) || (userNumber == 2)) ? ("%d is a prime number\n") : ("%d is a composite number\n"), userNumber); | ||
|
||
system("pause"); | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,4 +14,6 @@ | |
|
||
年级是他的一半。 | ||
|
||
问儿子死时丢番图多大? | ||
问儿子死时丢番图多大? | ||
|
||
/* *just for test* */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/* author: Kyrios0 | ||
* date: 2017.02.23 | ||
* version: 1.0.0 | ||
* state: finished | ||
*/ | ||
|
||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include <windows.h> | ||
|
||
int main(int argc, char *argv[]) { | ||
system("chcp 437"); | ||
system("cls"); | ||
double age = 0.0, ans = 0.0; | ||
while(1) | ||
{ | ||
ans = (1.0/6.0 + 1.0/12.0 + 1.0/7.0 + 1.0/2.0) * age + 9.0; | ||
if(ans - age < 0.1) | ||
{ | ||
printf("He was %.0f years old at that time. \n", ans - 4); | ||
system("pause"); | ||
return 0; | ||
} | ||
age += 1.0; | ||
} | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,4 +4,4 @@ | |
|
||
水仙花数:n位数的每个数位的n次方之和等于该n位数本身 | ||
|
||
例如:153=1^3+5^3+3^3 | ||
例如:153=1^3 + 5^3 + 3^3 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/* code: Narcissus | ||
* author: Kyrios0 | ||
* date: 2017.02.26 | ||
* state: finished | ||
* version: 1.0.0 | ||
*/ | ||
|
||
#include "stdafx.h" | ||
#include<stdio.h> | ||
#include<windows.h> | ||
#include<math.h> | ||
|
||
int main(int argc, char** argv) | ||
{ | ||
system("chcp 437"); | ||
system("cls"); | ||
int hun, ten, one, sum = 100;//hun = 100 | ||
puts("The following is the number of narcissus in 1000"); | ||
|
||
while (sum < 1000) | ||
{ | ||
one = sum % 10; | ||
ten = sum / 10 % 10; | ||
hun = sum / 100; | ||
|
||
if ((int)(pow(double(one), 3.0) + pow(double(ten), 3.0) + pow(double(hun), 3.0)) == sum) | ||
{ | ||
printf("%d\n", sum); | ||
} | ||
|
||
sum++; | ||
} | ||
|
||
system("pause"); | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
// allPrime.cpp | ||
// | ||
|
||
#include "stdafx.h" | ||
/* code: Linked list Step0 for eratosthenes | ||
* author: Kyrios0 | ||
* date: 2017.02.21 | ||
* state: finished | ||
* version: 1.0.2 | ||
*/ | ||
|
||
#include<stdio.h> | ||
#include<stdlib.h>//malloc() | ||
#include<string.h> | ||
#include<Windows.h> | ||
|
||
typedef struct linked { | ||
int data; | ||
linked *next; | ||
}linked; | ||
|
||
linked* creat(int length) | ||
{ | ||
linked *head, *tail, *p; | ||
int x; | ||
head = tail = NULL; | ||
|
||
for (x = 0; x < length; x++) | ||
{ | ||
p = (linked *)malloc(sizeof(linked)); | ||
p->data = x + 2;//0 and 1 aren't prime or composite number | ||
p->next = NULL; | ||
|
||
if (head == NULL) | ||
{ | ||
head = tail = p; | ||
} | ||
else | ||
{ | ||
tail = tail->next = p; | ||
} | ||
} | ||
|
||
return head; | ||
} | ||
|
||
|
||
|
||
int main(int argc, char** argv) | ||
{ | ||
long len = 10000000;//about 40s | ||
linked *current, *head, *temp, *currenthead; | ||
current = creat(len); | ||
head = current; | ||
currenthead = head; | ||
|
||
puts("Working..."); | ||
|
||
for (long i = 0; ; i++) | ||
{ | ||
if (i * i >= len)//Termination | ||
{ | ||
break; | ||
} | ||
|
||
while (current->next != NULL) | ||
{ | ||
temp = current->next; | ||
|
||
while (temp->data % currenthead->data == 0)//Delete this number | ||
{ | ||
current->next = temp->next; | ||
temp = temp->next; | ||
len--; | ||
if (temp == NULL) | ||
{ | ||
break; | ||
} | ||
} | ||
|
||
if (current->next == NULL) | ||
{ | ||
break; | ||
} | ||
else | ||
{ | ||
current = current->next; | ||
} | ||
} | ||
|
||
currenthead = currenthead->next; | ||
current = currenthead; | ||
} | ||
|
||
FILE *fpt; | ||
fpt = fopen("PrimeList.txt", "w"); | ||
|
||
puts("Start writing... Please wait a moment."); | ||
|
||
for (int i = 0; i < len; i++)//output | ||
{ | ||
fprintf(fpt, "%d, ", head->data); | ||
head = head->next; | ||
if ((i % 100000 == 0) && (i != 0)) | ||
{ | ||
printf("%d numbers has been writen: %d \n", i, head->data); | ||
} | ||
} | ||
|
||
puts("DONE!"); | ||
|
||
system("pause"); | ||
|
||
return 0; | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
这道题用链表干什么呢?
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.
实现一个简单的筛法..链表移除数据比数组方便...
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.
这个题和Goldbach都是偷懒从先写的lvl1_5改过来的...所以看起来比较奇怪...
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.
那段时间刚学链表。。。什么都想用链表做。现在看在反而是弄巧成拙了。。等有空了重新写一份顺便优化一下算法。。。