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 #34

Open
wants to merge 18 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
29 changes: 29 additions & 0 deletions level1/p01_runningLetter/奔跑的字母.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#include <stdio.h>
#include <stdlib.h>
#define LENGTH 119
int main(int argc, char *argv[])
{
int i,j,k;
for(i=1;i<=LENGTH;i++)
{
printf("a");
system("cls");
for(j=1;j<=i;j++)
{
printf(" ");
}
}
for(i=LENGTH;i>=1;i--)
{
printf("a");
system("cls");
for(j=i;j>=1;j--)
{
printf(" ");
}
}
system("cls");
printf("a");
system("pause");
return 0;
}
28 changes: 28 additions & 0 deletions level1/p02_isPrime/p02_isPrime.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char *argv[])
{
int i,n,k;
k=1;
loop:scanf("%d",&n);
Copy link
Owner

Choose a reason for hiding this comment

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

尽量不用goto,可尝试用while来代替

if(n<=0)
{
printf("������һ��������\n");
goto loop;
}
for(i=2;i<n;i++)
{
if(n%i==0)
{
k=0;
}
}
if(k==0||n==1||n==2)
{
printf("��������\n");
}
else
printf("������\n");
system("pause");
return 0;
}
15 changes: 15 additions & 0 deletions level1/p03_Diophantus/p03_Diophantus.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char *argv[])
{
float x;
for(x=1;x<=100;x++)
{
if(x*1/6+x*1/12+x*1/7+5+0.5*x+4==x)
{
printf("��ʱ����ͼ%.0f��\n",x-4);
}
}
system("pause");
return 0;
}
17 changes: 17 additions & 0 deletions level1/p04_ narcissus/p04_ narcissus.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char *argv[])
{
int i,a,b,c,n;
printf("3λˮ�ɻ�����\n");
for(i=100;i<=999;i++)
{
a=i/100;
b=(i/10)%10;
c=i%10;
if(i==a*a*a+b*b*b+c*c*c)
printf("%d=%d^3+%d^3+%d^3\n",i,a,b,c);
}
system("pause");
return 0;
}
37 changes: 37 additions & 0 deletions level1/p05_allPrimes/p05_allPrimes.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#include <stdio.h>
#include <time.h>
#include <stdlib.h>
#include <math.h>
#define N 2000
bool prime(int n)
{
int i,k;
k=1;
for(i=2;i<sqrt(n);i++)
{
if(n%i==0)
{
k=0;
}
}
return k;
}
int main(int argc, char *argv[])
{
int i,s;
clock_t start, finish;
double Total_time;
Copy link
Owner

Choose a reason for hiding this comment

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

缩进

start = clock();
for(i=2;i<=N;i++)
{
if(prime(i)==1)
{
printf("%d ",i);
}
}
printf("\n");
finish = clock();
Total_time = (double)(finish-start) / CLOCKS_PER_SEC;
printf( "time:%f seconds\n", Total_time);
return 0;
}
30 changes: 30 additions & 0 deletions level1/p06_Goldbach/p06_Goldbach.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#include <stdio.h>
#include <math.h>
bool prime(int n)
{
int i,k;
k=1;
for(i=2;i<sqrt(n);i++)
{
if(n%i==0)
{
k=0;
}
}
return k;
}
int main(int argc, char *argv[])
{
int i,j,t,n,s;
for(i=4;i<=100;i=i+2)
{
for(j=2;j<i;j++)
{
if((prime(j)==1)&&(prime(i-j)==1))
{
printf("%d=%d+%d\n",i,j,i-j);
}
}
}
return 0;
}
65 changes: 65 additions & 0 deletions level1/p07_encrypt_decrypt/p07_encrypt_decrypt_ASCII+5.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
#include <stdio.h>
#include <string.h>
#define LENGTH 100000
//�˼��ܷ���Ϊ���ַ���ASCII��+5
int encrypt(char s[])
{
int a[LENGTH];
int i;
for(i=1;i<=LENGTH;i++)
{
a[i]=-1;
}
for(i=0;i<strlen(s);i++)
{
a[i]=s[i];
}
for(i=0;i<strlen(s);i++)
{
if(a[i]!=-1)
{
a[i]=a[i]+5;
}
}
for(i=0;i<strlen(s);i++)
{
s[i]=(char)a[i];
}
return 0;
}
int decrypt(char s[])
{
int b[LENGTH];
int x;
for(x=1;x<=LENGTH;x++)
{
b[x]=-1;
}
for(x=0;x<strlen(s);x++)
{
b[x]=s[x];
}
for(x=0;x<strlen(s);x++)
{
if(b[x]!=-1)
{
b[x]=b[x]-5;
}
}
for(x=0;x<strlen(s);x++)
{
s[x]=(char)b[x];
}
return 0;
}
int main(int argc, char *argv[])
{
char s[LENGTH]="null";
int i;
scanf("%[^\n]",s);
encrypt(s);
printf("���ܺ�%s\n",s);
decrypt(s);
printf("���ܺ�%s\n",s);
return 0;
}
28 changes: 28 additions & 0 deletions level1/p08_hanoi/p08_hanoi.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#include <stdio.h>
#include <string.h>
#include <time.h>
void hanoi(int n,char a,char b,char c)
{
if(n==1)
printf("%c��%c\n",a,c);
else
{
hanoi(n-1,a,c,b);
printf("%c��%c\n",a,c);
hanoi(n-1,b,a,c);
}
}
int main(int argc, char *argv[])
{
int n;
printf("��������������");
scanf("%d",&n);
clock_t start, finish;
double Total_time;
Copy link
Owner

Choose a reason for hiding this comment

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

缩进

start = clock();
hanoi(n,'A','B','C');
finish = clock();
Total_time = (double)(finish-start) / CLOCKS_PER_SEC;
printf( "����ʱ�䣺%f seconds\n", Total_time);
return 0;
}
106 changes: 106 additions & 0 deletions level1/p09_maze/p09_maze.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#include <string.h>
int main(int argc, char *argv[])
{
int x,y,nkey,x0,y0;
char key;
char *a[100];
int i,j;
for(i=0;i<15;i++)
{
a[i] = (char*)malloc(sizeof(char)*100);
}


strcpy(a[0],"XXXXXXXXXXXXXXXXXXXXXX");
strcpy(a[1],"XXXXXXX X X ����");
strcpy(a[2],"XX XX X X X X XXXXXX");
strcpy(a[3],"X X X X X X XX");
strcpy(a[4],"X X X XXXXXX X XX");
strcpy(a[5],"X X XX X X X");
strcpy(a[6],"X X XXXXXX X XX X");
strcpy(a[7],"X XXX XX X X X X");
strcpy(a[8],"X X XX X X X X XX");
strcpy(a[9],"XXX X X X X X X X");
strcpy(a[10],"X X X X X X X X");
strcpy(a[11],"X XXX X X X XX X");
strcpy(a[12],"X XXX X XXXXXXX");
strcpy(a[13],"XoXXXXXXXXXXXXXXXXX");
strcpy(a[14]," <-�ɴ˽���");
x=13;y=1;
x0=13;y0=1;
printf("�Թ�С��Ϸ��w,s,a,d�������ң���ESC���˳������ǡ�o��\n");
printf("���������ʼ");
while(true)
{
a[14][1]='X';
point:key=getch();nkey=(int)key;
if(nkey==27)break;
if(y>20)
{
system("cls");
printf("��ϲ���߳��Թ�����");
break;
}
switch(key)
{
case 'w':
{
if(a[x-1][y]=='X')goto point;
if((x>0)&&(a[x-1][y]!='X'))
{
x--;
a[x0][y0]=' ';
a[x][y]='o';
x0=x;y0=y;
break;
}
}
case 'a':
{
if(a[x][y-1]=='X')goto point;
if((y>0)&&(a[x][y-1]!='X'))
{
y--;
a[x0][y0]=' ';
a[x][y]='o';
x0=x;y0=y;
break;
}
}
case 'd':
{
if(a[x][y+1]=='X')goto point;
if(a[x][y+1]!='X')
{
y++;
a[x0][y0]=' ';
a[x][y]='o';
x0=x;y0=y;
break;
}
}
case 's':
{
if(a[x+1][y]=='X')goto point;
if(a[x+1][y]!='X')
{
x++;
a[x0][y0]=' ';
a[x][y]='o';
x0=x;y0=y;
break;
}
}defalt:break;
}
system("cls");printf("�Թ�С��Ϸ��w,s,a,d�������ң���ESC���˳�\n");
for(i=0;i<15;i++)
{
printf("%s\n",a[i]);
}
}
system("pause");
return 0;
}
22 changes: 22 additions & 0 deletions level1/p09_maze/p09_maze/creatmap.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#include <string.h>
void createmap(char *a[100])
{
strcpy(a[0],"XXXXXXXXXXXXXXXXXXXXXX");
strcpy(a[1],"XXXXXXX X X ����");
strcpy(a[2],"XX XX X X X X XXXXXX");
strcpy(a[3],"X X X X X X XX");
strcpy(a[4],"X X X XXXXXX X XX");
strcpy(a[5],"X X XX X X X");
strcpy(a[6],"X X XXXXXX X XX X");
strcpy(a[7],"X XXX XX X X X X");
strcpy(a[8],"X X XX X X X X XX");
strcpy(a[9],"XXX X X X X X X X");
strcpy(a[10],"X X X X X X X X");
strcpy(a[11],"X XXX X X X XX X");
strcpy(a[12],"X XXX X XXXXXXX");
strcpy(a[13],"XoXXXXXXXXXXXXXXXXX");
strcpy(a[14]," <-�ɴ˽���");
}
Loading