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

作业lishiqian #60

Open
wants to merge 15 commits into
base: lishiqianhugh
Choose a base branch
from
23 changes: 23 additions & 0 deletions level1/p01_runningLetter/Runningletter.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@

#include<stdio.h>
#include<stdlib.h>
int main()
{
int i,j;
#define WIDTH 80
for(i=0;i<=WIDTH;i++)
{
for(j=0;j<i;j++)
printf(" ");
printf("R");
system("cls");
}
for(i=WIDTH;i>=0;i--)
{
for(j=0;j<=i-1;j++)
printf(" ");
printf("R");
system("cls");
}
return 0;
}
20 changes: 20 additions & 0 deletions level1/p02_isPrime/isPrime.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#include<stdio.h>
#include<math.h>
int main()
{
int i,n,j,s;
printf("Please input a positive integer amd I will tell you whether it is a prime: ");
scanf("%d",&n);
s=sqrt(double(n));
for(i=2;i<=s;i++)
{
j=n%i;
if(j==0)
break;
}
if(i>s)
printf("%d is a prime.",n);
else
printf("%d is not a prime.",n);
return 0;
}
14 changes: 14 additions & 0 deletions level1/p03_Diophantus/Diophantus.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#include<stdio.h>
int main()
{
int n; //The amount of years the father lived
for(n=1;n>0;n++)
{
if((n/6+n/12+n/7+5+n/2+4)==n&&n%12==0&&n%7==0)
{
printf("He is %d years old when his son died.",n-4);
break;
}
}
return 0;
}
19 changes: 19 additions & 0 deletions level1/p04_ narcissus/narcissus.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#include<stdio.h>
int main()
{
int n;
int i,j,k;
for(i=1;i<=9;i++)
{
for(j=0;j<=9;j++)
{
for(k=0;k<=9;k++)
{
n=i*100+j*10+k;
if(i*i*i+j*j*j+k*k*k==n)
printf("%d\n",n);
}
}
}
return 0;
}
25 changes: 25 additions & 0 deletions level1/p05_allPrimes/allPrimes.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#include<stdio.h>
#include<math.h>
#include<time.h>
#define N 1000
int main()
{
int n,m,s;
int begin,end;
begin=clock(); //���㿪ʼ��ʱ��
for(n=2;n<=N;n++)
{
s=sqrt(double(n));
for(m=2;m<=s;m++)
{
if(n%m==0)
break;
}
if(m>s)
printf("%d\n",n);
}
end=clock(); //���������ʱ��
printf("Calculation time: %dms",end-begin);
return 0;

}
35 changes: 35 additions & 0 deletions level1/p06_Goldbach/Goldbach.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#include<stdio.h>
#include<math.h>
#define N 100
int isprime(int a);
int main()
{
int n,a,w;
for(n=4;n<=N;n+=2)
{
w=0;
for(a=2;a<100;a++)
{
if(isprime(a)&&isprime(n-a))
w++;
}
if(w==0)
break;
}
if(n==102)
printf("It proves right.");
else
printf("It proves wrong.");
return 0;
}
int isprime(int a)
{
int i,s;
s=sqrt(double(a));
for(i=2;i<=s;i++)
{
if(a%i==0)
break;
}
return (i>s)? a:0;
}
37 changes: 37 additions & 0 deletions level1/p07_encrypt_decrypt/encrypt_decrypt.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#include<stdio.h>
#include<stdlib.h>
int i,n=0;
char *p;
char c;
void encrypt()
{
printf("encrypt:\n");
for(i=0;i<=n-1;i++)
{
printf("%c",char((int(p[i]))+5));
}
}
void decrypt()
{
printf("decrypt:\n");
for(i=0;i<=n-1;i++)
{
printf("%c",p[i]);
}
}
int main()
{
printf("Input a string: ");
p=(char *)malloc(sizeof(char));
while((c=getchar())!='\n')
{
n++;
p=(char *)realloc(p,n*sizeof(char));
p[n-1]=c;
}
encrypt();
printf("\n");
decrypt();
free(p);
return 0;
}
23 changes: 23 additions & 0 deletions level1/p08_hanoi/hanoi.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#include<stdio.h>
char a='A',b='B',c='C';
void change(int n,char p,char q,char m)
{
if(n==1)
{
printf("The 1 has been moved from %c to %c.\n",p,q);
}
else
{
change(n-1,p,m,q);
printf("The %d has been moved from %c to %c.\n",n,p,q);
change(n-1,m,q,p);
}
}
int main()
{
int n;
printf("The number: ");
scanf("%d",&n);
change(n,a,b,c);
return 0;
}
111 changes: 111 additions & 0 deletions level1/p09_maze/maze.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
#include<stdio.h>
#include<stdlib.h>
#include<conio.h>

char a[11][31]= {{"# ########################## #"},
{"# # # # # # # #"},
{"# # # ######### # # # # ##"},
{"# # # # # # ### # #"},
{"##### # ### # ## # # # ## #"},
{"# # # # # # # # # #"},
{"# ### # # # # #### # # # # ##"},
{"# # # # # ######## # # # #"},
{"# # ## # #"},
{"##############################"}};
static int m=0,n=1; //���
void change_1()
{
if(a[m][n]=='#')
m++;
else
{
a[m][n]='o';
a[m+1][n]=' ';
}

}

void change_2()
{
if(a[m][n]=='#')
m--;
else
{
a[m][n]='o';
a[m-1][n]=' ';
}

}

void change_3()
{
if(a[m][n]=='#')
n++;
else
{
a[m][n]='o';
a[m][n+1]=' ';
}

}

void change_4()
{
if(a[m][n]=='#')
n--;
else
{
a[m][n]='o';
a[m][n-1]=' ';
}

}
void location()
{
int c;
if((c=getch())!=0x1B)
{
switch(c)
{
case 0xE0:
switch(c=getch())
{
case 72: {m--; change_1();} break;
case 80: {m++; change_2();} break;
case 75: {n--; change_3();} break;
case 77: {n++; change_4();} break;
default:
break;
}
break;
default:
break;
}
}
}

void maze()
{
int i,j;
for(i=0;i<=9;i++)
{
for(j=0;j<=30;j++)
{
printf("%c",a[i][j]);
}
printf("\n");
}
location();
}

int main()
{
a[m][n]='o';
while(a[0][28]!='o')
{
maze();
system("cls");
}
printf("Congratulations!You make it!");
return 0;
}
11 changes: 11 additions & 0 deletions level1/p10_pushBoxes/maps/map1.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# ########################## #
# # # #
# # # #
# # # #
# # # #
# # # #
# # # #
# #
# #
##############################
records:
11 changes: 11 additions & 0 deletions level1/p10_pushBoxes/maps/map2.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# ########################## #
# # # #
# ## ##### ## # # #
## # # ### ## # # #
# # # # ## # #
# ######## ## # # # #
# # # # # #
# ## # # # ## #
# # #
##############################
records:
11 changes: 11 additions & 0 deletions level1/p10_pushBoxes/maps/map3.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# ########################## #
# ## # #
# ## ## ## # # #
## # # ### # # # # #
# # ## # # ### # #
# #### ## ## # # # # #
# # # # # #
# ## # # # # # # ### #
# #
##############################
records:
11 changes: 11 additions & 0 deletions level1/p10_pushBoxes/maps/map4.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# ########################## #
# # # # # #
# ######## # # #
# # # # # # # # #
# ## # ### ## # # # # # #
## # # # # # # #
# ### # # # # # ## # # # # #
# # # # # ### #### # #
# # ## # #
##############################
records��
Loading