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

原杨锴♂2018081303017 #29

Open
wants to merge 22 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
30 changes: 30 additions & 0 deletions level1/p01_runningLetter/runningLetter.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#include<stdio.h>
#include<stdlib.h>
#include<windows.h>
#define LENGTH 117
int main()
{
int flag=0,a=0;

while(1)
{
for(int i=a;i>0;--i)
printf(" ");

printf("Van");
Sleep(70);
system("cls");

if(a==0)
flag=0;
if(a==length)
flag=1;

if(flag)
--a;
else
++a;
}

return 0;
}
31 changes: 31 additions & 0 deletions level1/p02_isPrime/isPrinme.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#include<stdio.h>
#include<math.h>
int main()
{
int n,flag=1;

scanf("%d",&n);
if(n<=1)
{
printf("%d不是素数\n",n);
flag=0;
}
if(n%6!=1&&n%6!=5&&n>6)//如果n大于6且不与6的倍数为邻 ,n不是素数
printf("%d不是素数\n",n);
else
{
for(int a=sqrt(n);a>=2;--a)
{
if(n%a==0)
{
printf("%d不是素数\n",n);
flag=0;
break;
}
}
if(flag)
printf("%d是素数\n",n);
}

return 0;
}
15 changes: 15 additions & 0 deletions level1/p03_Diophantus/Diophantus.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#include<stdio.h>
int main()
{
for(int age=12;age<=200;++age)//不能再多了
{
if(age%12==0&&age%7==0)
{
int x=age/6+age/12+age/7+5+age/2+4;
if(x==age)
printf("%d",x-4);
Copy link
Owner

Choose a reason for hiding this comment

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

缩进不对,加大括号

}
}

return 0;
}
18 changes: 18 additions & 0 deletions level1/p04_ narcissus/narcissus.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#include<stdio.h>
#include<math.h>
#define max 3

int main()
{
int all=0;
for(int x=100;x<1000;++x)
{
for(int i=0;i<max;++i)
all+=(int)pow((int)(x/pow(10,i))%10,max);
if(x==all)
printf("%d ",x);
all=0;
}

return 0;
}
48 changes: 48 additions & 0 deletions level1/p05_allPrimes/allPrimes.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#include<stdio.h>
#include<math.h>
#include<time.h>

clock_t start, stop;
double duration;

int main()
{
start = clock();

int num[999];
for(int i=0;i<999;++i)//为每个数匹配一个状态,起初默认均为素数(1)
{
num[i]=1;
}
for(int shu=2;shu<=1000;++shu)//对每个数进行判断
{
if(1==num[shu-2])// 如果还未被判断不是素数 (0)
{
for(int q=sqrt(shu);q>1;--q)//暴力判断此数是否为素数
{
if(0==shu%q)//如果不是素数,标记状态(0)
{
num[shu-2]=0;
}
}
if(1==num[shu-2])//如果此数为素数
{
for(int i=2;shu*i<=1000;++i)//标记此素数的倍数为非素数(0)
{
num[shu*i-2]=0;
}
}
}
}
for(int i=0;i<999;++i)//对每个数,如果是素数(1)则输出
{
if(1==num[i])
printf("%d\n",i+2);
}

stop = clock();
duration = ((double)(stop - start))/CLK_TCK;
printf("运行时间为%fs\n",duration);

return 0;
}
45 changes: 45 additions & 0 deletions level1/p06_Goldbach/Goldbach.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#include<stdio.h>
#include<math.h>
#define MAX 100

int isprime(int n);

int main()
{
for(int i=2,num=4;num<MAX;++i,num=2*i)
{
for(int d=0;d<num/2;++d)
{
int flag_1=isprime(num/2-d);
int flag_2=isprime(num/2+d);
if(flag_1&&flag_2)
{
printf("ż��%d�ɱ���ʾΪ����%d��%d�ĺ�\n",num,num/2-d,num/2+d);
break;
}
}
}

return 0;
}

int isprime(int n)
{
int flag=1;

if(n%6!=1&&n%6!=5&&n>6)//���n����6�Ҳ���6�ı���Ϊ�� ,n��������
flag=0;
else
{
for(int a=sqrt(n);a>=2;--a)
{
if(n%a==0)
{
flag=0;
break;
}
}
}

return flag;
}
32 changes: 32 additions & 0 deletions level1/p07_encrypt_decrypt/jiamijiemi.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#include<stdio.h>
#define LENGTH 500

int main()
{
char text[LENGTH];

printf("Please choose the operation you want:\nEnter E to encrypt\nEnter D to decrypt\n");
char choice=getchar();
if(choice=='E')
{
printf("Please enter the text needs to be encrypted:\n");
scanf("%s",&text);
for(int i=0;i<strlen(text);++i)
{
text[i]+=1;
}
printf("%s",text);

}
if(choice=='D')
{
printf("Please enter the text needs to be decrypted:\n");
scanf("%s",&text);
for(int i=0;i<strlen(text);++i)
{
text[i]-=1;
}
printf("%s",text);
}
return 0;
}
28 changes: 28 additions & 0 deletions level1/p08_hanoi/hanoi.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#include <stdio.h>

void move(char x, char y);
void hanoi(int n,char one ,char two,char three)
{
void move(char x,char y);
if(n==1)
move(one, three);
else
{
hanoi(n-1,one,three,two);
move(one,three);
hanoi(n-1,two,one,three);
}
}
void move(char x,char y)
{
printf("%c-->%c\n",x,y);
}

void main()
{
int n;
printf("input your number");
scanf("%d",&n);
hanoi(n,'A','B','C');
return 0;
}
73 changes: 73 additions & 0 deletions level1/p09_maze/maze.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
#include<stdio.h>
#include<stdlib.h>
#include<conio.h>

int main()
{
int y=1,x=1;
int maze[11][11]=
{
{1,1,1,1,1,1,1,1,1,1,1},
{1,8,1,0,0,0,0,0,0,0,1},
{1,0,1,0,1,0,1,1,1,0,1},
{1,0,1,0,1,0,1,0,0,0,1},
{1,0,0,0,1,0,1,0,1,1,1},
{1,1,1,1,1,0,1,0,1,2,1},
{1,0,0,0,0,0,0,0,1,0,1},
{1,0,1,1,1,1,1,1,1,0,1},
{1,0,1,0,0,0,1,0,0,0,1},
{1,0,0,0,1,0,0,0,1,0,1},
{1,1,1,1,1,1,1,1,1,1,1}
};

while(maze[5][9]==2)
{
for(int i=0,j=0;i<11;++i)
{
for(;j<11;++j)
{
if(maze[i][j]==0)
printf(" ");
if(maze[i][j]==1)
printf("#");
if(maze[i][j]==2)
printf("C");
if(maze[i][j]==8)
printf("Y");
}
if(j==11)
{
j=0;
printf("\n");
}
}
char move=_getch();
if(move==75&&maze[y][x-1]!=1)
{
maze[y][x]=0;
maze[y][x-1]=8;
x-=1;
}
if(move==77&&maze[y][x+1]!=1)
{
maze[y][x]=0;
maze[y][x+1]=8;
x+=1;
}
if(move==72&&maze[y-1][x]!=1)
{
maze[y][x]=0;
maze[y-1][x]=8;
y-=1;
}
if(move==80&&maze[y+1][x]!=1)
{
maze[y][x]=0;
maze[y+1][x]=8;
y+=1;
}
system("cls");
}
printf("You win!!!\n");
return 0;
}
Loading