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

2017.03.11 #51

Open
wants to merge 20 commits into
base: master
Choose a base branch
from
Open
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
34 changes: 34 additions & 0 deletions practices/c/level1/p01_runningLetter/runningletter.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/* system("color 0a");
while(1){
printf("0 1");
*/
#include<stdio.h>
#include<Windows.h>
int main()
{
system("color 0a");

int i,j;

while(1){
for(i = 0 ; i < 49 ; i++){
for(j = 0 ; j < i ; j++){
printf(" ");
}
printf("R");
system("cls");
}
for(i = 49 ; i > -1 ; i--){
for(j = i ; j > -1 ; j--){
printf(" ");
}
printf("R");
system("cls");
}
}

return 0;
}



19 changes: 19 additions & 0 deletions practices/c/level1/p02_isPrime/isPrimes.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#include<stdio.h>
int main()
{
int a,n = 0;

scanf("%d",&a);
for(int i = 2 ; i < a ; i++){
if(a%i == 0){
n = 1;
}
}
if(n == 0){
printf("yes");
}else{
printf("no");
}

return 0;
}
17 changes: 17 additions & 0 deletions practices/c/level1/p03_Diophantus/Diophantus.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
//����ͼ��ͯ�꾭������һ��������֮һ�����꾭����ʮ����֮һ�������߷�֮һ��ʱ���ǵ�������
//����������˸����ӣ����ӱȸ����������꣬�꼶������һ�롣�ʶ�����ʱ����ͼ���
#include<stdio.h>
int main()
{
int a;
for(a = 60 ; a < 150 ; a++){
if(a%6 == 0){
if(a%12 == 0){
if(a%7 == 0){
printf("%d\n",a);
}
}
}
}
return 0;
}
18 changes: 18 additions & 0 deletions practices/c/level1/p04_ narcissus/shuixianhuashu.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#include<stdio.h>
main()
Copy link
Owner

Choose a reason for hiding this comment

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

main函数也需要返回类型

{
printf("��λ����ˮ����Ϊ:\n");
for(int a = 100 ; a < 1000 ; a++)
{
int hun = a/100;
int ten = a/10-hun*10;
int one = a-hun*100-ten*10;

if(a == hun*hun*hun+ten*ten*ten+one*one*one)
{
printf("%d\t",a);
}

}
return 0;
}
30 changes: 30 additions & 0 deletions practices/c/level1/p05_allPrimes/level1_allPrimes.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
1. ��ӡ2-1000���ڵ���������
2. ��ӡ���ܵļ���ʱ��
3. �������Ż��㷨��Ч��
*/
#include<stdio.h>
#include<time.h>
#include<Windows.h>
int main()
{
system("color 0a");
clock_t t1 = clock();
for(int a = 2 ; a < 999 ; a++){
int n = 0;
for(int i = 2 ; i < a ; i++){
if(a%i == 0){
n = 1;
break;
}
}
if(n == 0){
printf("%d\t",a);

}
}
clock_t t2 = clock();

printf("\nTime=%d",t2-t1);
return 0;
}
40 changes: 40 additions & 0 deletions practices/c/level1/p06_Goldbach/Goldbash.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#include<stdio.h>

bool isPrimes(int n);

int main()
{
int m,n;
int num = 0;

for(int i = 2 ; i < 98 ; i = i+2){
for(n = 1 ; n < i ; n++){

int truth = 0;
m = i-n;

if(isPrimes(n)&&isPrimes(m)){
truth = 1;
if(truth == 1){
num++;
break;
}
}

}
}
if(num == 48){
printf("this propersition is right");
}
return 0;
}

bool isPrimes(int n)
{
for(int i = 2 ; i < n ; i++){
if(n%i == 0){
return false;
}
}
return true;
}
66 changes: 66 additions & 0 deletions practices/c/level1/p07_encrypt_decrypt/encrypt.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
#include<stdio.h>//?������

void decrypt();
void encrypt();

int main()
{
int choice;
printf("Would you want to decrypt(1) or encrypt(2)?");
scanf("%d",&choice);
if(choice==1){
decrypt();
}else{
encrypt();
}
return 0;
}


void encrypt()
{
int n,j=0;
char ch[80],tran[80];
printf("input cipher code:");
gets(ch);
printf("\ncopher code :%s",ch);
for(j;ch[j]!='\0'; j++){
if((ch[j]>='A')&&(ch[j]<='Z')){
tran[j]=155-ch[j];
}else if((ch[j]>='a')&&(ch[j]<='z')){
tran[j]=219-ch[j];
}else {
tran[j]=ch[j];
}
n=j;
printf("\noriginal text:");
for(j=0;j<n;j++){
putchar(tran[j]);
}
}
}

void decrypt()
{
int n,j=0;
char ch[80],tran[80];
printf("input original code:");
gets(ch);
printf("\noriginal code :%s",ch);
for(j;ch[j]!='\0'; j++){
if((ch[j]>='A')&&(ch[j]<='Z')){
tran[j]=155-ch[j];
}else if((ch[j]>='a')&&(ch[j]<='z')){
tran[j]=219-ch[j];
}else {
tran[n]=ch[j];
}
n=j;
printf("\ncipher text:");
for(j=0;j<n;j++){
putchar(tran[j]);
}
}

}

31 changes: 31 additions & 0 deletions practices/c/level1/p08_hanoi/hanoi.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#include<stdio.h>

void hanoi(int n,char a,char b,char c);
void move(char x,char y);

int main()
{
int m;
printf("input the number of diskes:");
scanf("%d",&m);
hanoi(m,'A','B','C');

return 0;
}


void hanoi(int n,char a,char b,char c)
{
if(n==1){
move(a,c);
}else{
hanoi(n-1,a,c,b);
move(a,c);
hanoi(n-1,b,a,c);
}
}

void move(char x,char y)
{
printf("%c-->%c\n",x,y);
}
27 changes: 20 additions & 7 deletions practices/c/level1/p09_maze/README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,20 @@
### 题目:迷宫小游戏(基于console)

### 功能要求:

1. 在控制台上显示一个迷宫,包括:墙、玩家、出口等;
2. 通过上下左右键,控制玩家行走;
3. 当玩家到达出口,则显示玩家赢得了游戏;
### 题目:迷宫小游戏(基于console)

### 功能要求:

1. 在控制台上显示一个迷宫,包括:墙、玩家、出口等;
2. 通过上下左右键,控制玩家行走;
3. 当玩家到达出口,则显示玩家赢得了游戏;


0 0000000000000000
0 0
00 000000000000000
0 0
000 00000000000000
0 0
0000 0000000000000
0 0
00000 000000000000
0 0
000000 00000000000
Binary file added practices/c/level1/p09_maze/gmon.out
Binary file not shown.
Loading