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

完成了running letter #39

Open
wants to merge 19 commits into
base: master
Choose a base branch
from
Open
446 changes: 446 additions & 0 deletions level0/level0.c

Large diffs are not rendered by default.

22 changes: 22 additions & 0 deletions level1/p01_runningLetter/runningR.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#include<stdio.h>
#define WIDTH 119
int main()
{
int r=0,i=0,j=0;
while(1)
{
for(i=0;i<WIDTH;i++)
{
for(j=0;j<=i;j++)printf(" ");
printf("R");
system("cls");
}
for(i=WIDTH-1;i>=0;i--)
{
for(j=i-1;j>=0;j--)printf(" ");
printf("R");
system("cls");
}
}
return 0;
}
20 changes: 20 additions & 0 deletions level1/p02_isPrime/isPrime.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
p02
#include<stdio.h>
int main()
{
int n,i;
int first=1;
scanf("%d",&n);
for(i=2;i*i<=n;i++)
{
if(n%i==0){
first=0;
break;
}
}
if(first)
printf("n is a prime.");
else
printf("n is not a prime.");
return 0;
}
20 changes: 20 additions & 0 deletions level1/p03_Diophantus/Diophantus.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#include<stdio.h>
int main()
{
int i,j,dezi;
for(i=1;i<=200;i++)
{//age of father
if(i%6==0&&i%12==0&&i%7==0)
{
dezi=i/6+i/12+i/7+5;
for(j=1;j<=100;j++)
{//age of son
if(dezi+j+4==i&&j==i/2&&i%2==0)
{
printf("When his son died, he is %d years old.",i-4);
return 0;
}
}
}
}
}
20 changes: 20 additions & 0 deletions level1/p04_ narcissus/narcissus.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
p04
#include<stdio.h>
int trisum(int n)
{
int a,b,c;
a=n%10;
b=(n/10)%10;
c=n/100;
return a*a*a+b*b*b+c*c*c;
}
int main()
{
int a,b,c,i;
for(i=100;i<1000;i++)
{
if(i==trisum(i))
printf("%d\n",i);
}
return 0;
}
27 changes: 27 additions & 0 deletions level1/p05_allPrimes/allPrimes.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
p05
#include<stdio.h>
#include<time.h>
#define maxn 10000000
clock_t start,stop;
double duration;
int p[maxn+5];
int main()
{
int i,j;
for(i=2;i<=maxn;i++)
p[i]=1;
start=clock();
for(i=2;i<=maxn;i++)
{
if(p[i])
for(j=2*i;j<=maxn;j=j+i)
p[j]=0;
}
stop=clock();
duration=((double)(stop-start))/CLK_TCK;
for(i=2;i<=maxn;i++)
if(p[i])
printf("%d ",i);
printf("\nThe time is %lf seconds",duration);
return 0;
}
23 changes: 23 additions & 0 deletions level1/p06_Goldbach/Goldbach.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#include<stdio.h>
int main()
{
int p[110];
int i,j,ans1,ans2;
for(i=2;i<=100;i++)p[i]=1;
for(i=2;i<=100;i++)
{
for(j=2*i;j<=100;j=j+i)p[j]=0;
}
for(i=2;i<=100;i++)if(i%2==0)
{
for(j=2;j<=50;j++)
if(p[j]&&i-j>1&&p[i-j])
{
ans1=j;
ans2=i-j;
printf("%d=%d+%d\n",i,j,i-j);
break;
}
}
return 0;
}
34 changes: 34 additions & 0 deletions level1/p07_encrypt_decrypt/encrypt_decrypt.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#include<stdio.h>
#include<string.h>
char string[1000];
void encrypt(char *s);
void decrypt(char *s);
int main()
{
gets(string);
encrypt(string);
puts(string);
decrypt(string);
puts(string);
return 0;
}
void encrypt(char *s)
{
int i,len;
len=strlen(s);
for(i=0;i<len;i++)
{
s[i]=s[i]+1;
}
return;
}
void decrypt(char *s)
{
int i,len;
len=strlen(s);
for(i=0;i<len;i++)
{
s[i]=s[i]-1;
}
return;
}
23 changes: 23 additions & 0 deletions level1/p08_hanoi/Hanoi.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#include<stdio.h>
int count=0;
int hanoi(int n,char A,char B,char C)
{
if(n==1){
printf("%c-->%c\n",A,B);
count++;
return;
}
hanoi(n-1,A,C,B);
printf("%c-->%c\n",A,B);count++;
hanoi(n-1,C,B,A);
return count;
}
int main()
{
int n;
scanf("%d",&n);
int count;
count=hanoi(n,'A','B','C');
printf("%d",count);
return 0;
}
Binary file removed level1/p08_hanoi/hanoi.jpg
Binary file not shown.
22 changes: 22 additions & 0 deletions level1/p09_maze/maze.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#####################
# # # #
# ### # # # ###
# # # # # # # #
######### # # # ### #
# # # # # # #
# ##### ### # # ### #
# # # # # #
### ##### ####### ###
# # #
# ##### ### ####### #
# # # # #
##### ### ####### # #
# # # # # #
# ##### # # # # # ###
# # # # # # # # #
# ### # # # # ##### #
# # # # # # # #
# # # # # # # # ### #
# # # # # #
#####################

106 changes: 106 additions & 0 deletions level1/p09_maze/迷宫.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
char mazemap[50][50];
void show();
int x=11,y=0;
int main()
{
FILE *fin;
fin = fopen("/tmp/maze.txt","r");
int i,j;
for(i=0;i<21;i++)
{
fgets(mazemap[i],25,fin);
}
show(x,y);
char c;
while((c=getch())!=-1)
{
if(c=='a')
{
if(y>0&&mazemap[x][y-1]!='#')
{
y--;
show(x,y);
}
}
else if(c=='s')
{
if(x<20&&mazemap[x+1][y]!='#')
{
x++;
show(x,y);
}
}
else if(c=='d')
{
if(y<20&&mazemap[x][y+1]!='#')
{
y++;
show(x,y);
}
}
else if(c=='w')
{
if(x>0&&mazemap[x-1][y]!='#')
{
x--;
show(x,y);
}
}
else if(c=='g')
{
show(x,y);
printf("лл���룡");
break;
}
else
{
printf("��������");
}
if(x==13&&y==20)
{
printf("ף�أ���ɹ��ˣ�");
break;
}
}


fclose(fin);
return 0;
}
void show(int x,int y)
{
system("cls");
printf("a:�� s:�� w:�� d:�� g:����\n");
int i,j;
for(i=0;i<21;i++)
{
for(j=0;j<21;j++)
{
if(i==x&&j==y)
{
printf("$");
continue;
}
printf("%c",mazemap[i][j]);
}
printf("\n");
}
return;
}














Loading