-
Notifications
You must be signed in to change notification settings - Fork 33
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
王益龙 #17
Open
iku-iku-iku
wants to merge
7
commits into
luckymark:master
Choose a base branch
from
iku-iku-iku:master
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
王益龙 #17
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
0569ed9
完成了running letter
iku-iku-iku 99f952d
finished some
iku-iku-iku 93018aa
finished some
iku-iku-iku af40af8
nice
iku-iku-iku badab6c
all finished....
iku-iku-iku cd175f4
Modified a little
iku-iku-iku ec02100
修改了一些
iku-iku-iku 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
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,66 @@ | ||
#include <stdio.h> | ||
#include <windows.h> | ||
#include <time.h> | ||
#include <string.h> | ||
//constants | ||
enum{ N = 1000 , SLEEP_TIME = 50}; | ||
char space[N]; | ||
int i; | ||
//func | ||
int GetWidth(); | ||
int abs(int x); | ||
//entertainment | ||
void DrawLine(int width); | ||
void ChangeColor(int cnt); | ||
|
||
int main(int argc, char const *argv[]) | ||
{ | ||
printf("Please enter several letters within a line:\n"); | ||
//Init | ||
char str[N]; scanf("%s",str); | ||
int len = strlen(str); | ||
int width = GetWidth(); | ||
int pos; | ||
//Play | ||
int cnt = 0; | ||
while (1) { | ||
/*calculate pos*/ | ||
pos = width - abs(width - ( cnt++ % (2 * width) ) ); | ||
/*prevent crossing the border*/ | ||
if (pos + len > width) continue; | ||
|
||
ChangeColor(cnt); | ||
system("cls"); | ||
DrawLine(width); | ||
/*Output*/ | ||
for (i = 0; i < width; ++ i) | ||
space[i] = i < pos || i >= pos + len ? ' ' : str[i - pos]; | ||
space[i] = '\0'; | ||
printf("%s",space); | ||
|
||
DrawLine(width); | ||
/*Sleep a while, let the user watch.*/ | ||
Sleep(SLEEP_TIME); | ||
} | ||
return 0; | ||
} | ||
int GetWidth() | ||
{ | ||
CONSOLE_SCREEN_BUFFER_INFO scr; | ||
HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE); | ||
GetConsoleScreenBufferInfo(hOut, &scr); | ||
return scr.dwMaximumWindowSize.X; | ||
} | ||
int abs(int x) | ||
{ | ||
return x >= 0 ? x : -x; | ||
} | ||
void DrawLine(int width) | ||
{ | ||
for (i = 0; i < width; ++ i) space[i] = '*'; space[i] = '\0'; | ||
printf("%s\n",space); | ||
} | ||
void ChangeColor(int cnt) { | ||
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),cnt % 16); | ||
// SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),(cnt % 16) * 16 + 16 - (cnt % 16)); | ||
} |
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,17 @@ | ||
#include <stdio.h> | ||
int main(){ | ||
int n,i; | ||
scanf("%d",&n); | ||
if (n <= 1) { | ||
printf("error"); | ||
return 0; | ||
} | ||
for (i = 2; i <= n / i; ++ i) { | ||
if (n % i == 0) { | ||
printf("Not prime."); | ||
return 0; | ||
} | ||
} | ||
printf("Is prime."); | ||
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,12 @@ | ||
#include <stdio.h> | ||
int main(){ | ||
double t; | ||
for (t = 5; ; ++ t) { | ||
if (t / 6 + t / 12 + t / 7 + 5 + t / 2 + 4 == t) { | ||
printf("%g\n",t - 4); | ||
break; | ||
} | ||
} | ||
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,17 @@ | ||
#include <stdio.h> | ||
int is_narcissus(int x){ | ||
int a = x / 100; | ||
int c = x % 10; | ||
int b = (x - a * 100 - c) / 10; | ||
if (x == a * a * a + b * b * b + c * c * c) | ||
return 1; | ||
else return 0; | ||
} | ||
int main(){ | ||
int i; | ||
for (i = 100; i <= 999; ++ i) { | ||
if (is_narcissus(i)) printf("%d\n",i); | ||
} | ||
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,32 @@ | ||
#include <stdio.h> | ||
#include <time.h> | ||
enum {N = 1001}; | ||
int primes[N], cnt; | ||
int sieved[N]; | ||
|
||
void get_primes(int n); | ||
int main(int argc, char const *argv[]) | ||
{ | ||
clock_t timer = clock(); | ||
get_primes(1000); | ||
int i; | ||
for (i = 0; i < cnt; ++ i) { | ||
printf("%d\t",primes[i]); | ||
} | ||
printf("\nTime:%dms\n",clock() - timer); | ||
system("pause"); | ||
return 0; | ||
} | ||
void get_primes(int n) | ||
{ | ||
int i,j; | ||
for (i = 2; i <= n; i ++ ) | ||
{ | ||
if (!sieved[i]) primes[cnt ++ ] = i; | ||
for (j = 0; primes[j] <= n / i; j ++ ) | ||
{ | ||
sieved[primes[j] * i] = 1; | ||
if (i % primes[j] == 0) break; | ||
} | ||
} | ||
} |
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,33 @@ | ||
#include <stdio.h> | ||
enum {N = 100}; | ||
int sieved[N + 1]; | ||
int primes[N + 1],cnt; | ||
int i,j,k,l; | ||
void init_primes(); | ||
int main(){ | ||
init_primes(); | ||
for (i = 6; i <= N; ++ i){ | ||
for (j = 0; j < cnt; ++ j) | ||
for (k = 0; k < cnt; ++ k) | ||
for (l = 0; l < cnt; ++ l) | ||
if (primes[j] + primes[k] + primes[l] == i) { | ||
printf("%d == %d + %d + %d\n",i,primes[j],primes[k],primes[l]); | ||
goto flag; | ||
} | ||
printf("It is wrong within 100!"); | ||
flag: | ||
; | ||
} | ||
printf("It is verified that Goldbach conjecture is right within 100.\n"); | ||
system("pause"); | ||
return 0; | ||
} | ||
void init_primes(){ | ||
for (i = 2; i <= N; ++ i) { | ||
if (!sieved[i]) { | ||
primes[cnt ++] = i; | ||
for (j = i + i; j <= N; j += i) | ||
sieved[j] = 1; | ||
} | ||
} | ||
} |
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,74 @@ | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
char book[] = "18381048095"; | ||
typedef struct string { | ||
char * str; | ||
int length; | ||
int capacity; | ||
} string; | ||
void get_str(string * str); | ||
void init_str(string * str); | ||
void update(string * str); | ||
void encrypt(string * str); | ||
void decrypt(string * str); | ||
void showStr(string * str); | ||
int main(int argc, char const *argv[]) | ||
{ | ||
printf("Please enter the letters:\n"); | ||
string * str = (string *)malloc(sizeof(string)); | ||
get_str(str); | ||
char ch; | ||
printf("Enter 'e' to encrypt it, 'd' to decrypt it and 'q' to quit.\n"); | ||
while (ch = getchar()) { | ||
if (ch == 'q') break; | ||
else if (ch == 'e') encrypt(str); | ||
else if (ch == 'd') decrypt(str); | ||
else if (ch == '\n') continue; | ||
else { | ||
printf("Invalid input!\n"); | ||
continue; | ||
} | ||
showStr(str); | ||
} | ||
return 0; | ||
} | ||
void showStr(string * str) { | ||
int i; | ||
for (i = 0; i < str->length; ++ i){ | ||
putchar(str->str[i]); | ||
} | ||
putchar('\n'); | ||
} | ||
void encrypt(string * str) { | ||
int i; | ||
for (i = 0; i < str -> length; ++ i) str -> str[i] += book[i % 11] - '0'; | ||
} | ||
void decrypt(string * str) { | ||
int i; | ||
for (i = 0; i < str -> length; ++ i) str -> str[i] -= book[i % 11] - '0'; | ||
} | ||
void get_str(string * str) { | ||
init_str(str); | ||
char ch; | ||
while (ch = getchar()) { | ||
if (ch == '\n') break; | ||
update(str); | ||
str->str[str->length++] = ch; | ||
} | ||
} | ||
void init_str(string * str) { | ||
str -> length = 0; | ||
str -> capacity = 10; | ||
str -> str = (char*)malloc(sizeof(char) * str -> capacity); | ||
} | ||
void update(string * str) { | ||
if (str -> length > str -> capacity - 3) { | ||
str -> capacity += str -> capacity / 2; | ||
|
||
char * p = (char*)malloc(sizeof(char) * str -> capacity); | ||
int i; | ||
for (i = 0; i < str -> length; ++ i) | ||
p[i] = str -> str[i]; | ||
str -> str = p; | ||
} | ||
} |
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,15 @@ | ||
#include <stdio.h> | ||
void hanoi(int n,char origin,char medium,char dest) { | ||
if (n == 1) { | ||
printf("%c -> %c\n", origin, dest); | ||
return; | ||
} | ||
hanoi(n-1,origin,dest,medium); | ||
printf("%c -> %c\n", origin, dest); | ||
hanoi(n-1,medium,origin,dest); | ||
} | ||
int main() { | ||
int n = 3; | ||
hanoi(n,'A','B','C'); | ||
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.
漂亮的函数原型!