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
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.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#include<stdio.h>
Copy link
Owner

Choose a reason for hiding this comment

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

源代码的文件后缀应该是 .c

#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(" ");
Copy link
Owner

Choose a reason for hiding this comment

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

缩进不对

printf("R");
system("cls");
}
for(i=WIDTH-1;i>=0;i--)
{
Copy link
Owner

Choose a reason for hiding this comment

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

这两段代码有点像,请尝试消除重复部分

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/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++)
Copy link
Owner

Choose a reason for hiding this comment

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

缩进混乱了

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;
}
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;
}
6 changes: 6 additions & 0 deletions test.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#include<stdio.h>
Copy link
Owner

Choose a reason for hiding this comment

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

这个文件删掉吧

int main()
{
printf("hello world");
return 0;
}