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

2018081303016 提交作业 #68

Open
wants to merge 11 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
5 changes: 0 additions & 5 deletions C语言学习笔记.md

This file was deleted.

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# c2019
git# c2019

## 基本操作流程

Expand Down
21 changes: 21 additions & 0 deletions level1/p01_runningLetter/running letter.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#include<stdio.h>
#include<stdlib.h>
int main ()
{
int i,j,a,b;
for(i=0;i<=80;i++){
for(j=0;j<i;j++){
printf(" ");
}
printf("%c ",'R');
system("cls");
}
for(a=80;a>=0;a--){
for(b=0;b<=a;b++){
printf(" ");
}
printf("%c ",'R');
system("cls");
}
return 0;
}
18 changes: 18 additions & 0 deletions level1/p02_isPrime/2isprime.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#include<stdio.h>
#include<stdlib.h>
//isprime
int main()
{
int i,n;
printf("enter a number: ");
scanf("%d",&n);
for(i=2;i*i<=n;i++){
if(n%i==0)
break;
}
if(i*i>n)
printf("prime");
else
printf("not prime") ;
return 0;
}
15 changes: 15 additions & 0 deletions level1/p03_Diophantus/3.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#include<stdio.h>
#include<stdlib.h>
int main()
{
int i ;
for (i = 12; i <= 150; i++) {
if (i % 12 == 0 && i % 7==0) {
if (i == 75 * i / 84 + 9)
break;
}
}
printf("������ʱ����ͼΪ��%d\n",i);
system("pause");
return 0;
}
16 changes: 16 additions & 0 deletions level1/p04_ narcissus/4.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#include<stdio.h>
#include<stdlib.h>
//ˮ����
int main()
{
int i,a,b,c;
for(i=100;i<1000;i++){
a=i%10;
b=(i%100)/10;
c=i/100;
if(i==a*a*a+b*b*b+c*c*c)
printf("%d,",i);
}
system("pause");
return 0;
}
25 changes: 25 additions & 0 deletions level1/p05_allPrimes/5.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
//��������ʱ
int main()
{
int i,d;
clock_t start,finish;
double t;
start=clock();
for(i=2;i<=1000;i++){
for(d=2;d*d<=i;d++){
if(i%d==0)
break;
}
if(d*d>i)
printf("%d ,",i);
}
finish=clock();
printf("\n");
t=(double)(finish-start)/CLOCKS_PER_SEC;
printf("%f",t);
system("pause");
return 0;
}
33 changes: 33 additions & 0 deletions level1/p06_Goldbach/6.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#include<stdio.h>
#include<stdlib.h>

// ��100��Χ����֤��°ͺղ������ȷ�� ֤100������һ����2��ż������д����������֮��
int prime(int n)
{
int d,result;
for(d=2;d*d<=n;d++){
if(n%d==0)
break;
}
if(d*d>n)//����
result=0;
else
result=1;
return(result);
}
int main()
{
int i,j;
for(i=4;i<=100;i=i+2){
for(j=2;j<i;j++){
if(prime(j)==0&&prime(i-j)==0)
break;
}
if(j<i)
printf("%d %d %d\n",i,j,i-j);
else
printf("%d is wrong",i);
}
system("pause");
return 0;
}
30 changes: 30 additions & 0 deletions level1/p07_encrypt_decrypt/7^.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#include <stdio.h>
#include <string.h>
#define LENGTH 100000
#define add 3
int encrypt(char c[])
{
int i;
for(i=0;i<strlen(c);i++){
c[i]=c[i]+add;
}
return 0;
}
int decrypt(char c[])
{
int j;
for(j=0;j<strlen(c);j++){
c[j]=c[j]-add;
}
return 0;
}
int main()
{
char c[LENGTH];
gets(c);
encrypt(c);
printf("encrypt as: %s\n",c);
decrypt(c);
printf("decrypt as: %s\n",c);
return 0;
}
23 changes: 23 additions & 0 deletions level1/p08_hanoi/8.hanoi.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#include <stdio.h>
void hanoi(int n,char a,char b,char c)
{
if(1==n)
{
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 n;
printf("Input the number of diskes:");
scanf("%d",&n);
hanoi(n,'A','B','C');
return 0;
}
30 changes: 30 additions & 0 deletions level1/p09_maze/function.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#include"maze.h"
void move_1(char map[][20],int *px,int *py){
if(map[*px-1][*py]!='#'){
map[*px][*py]=' ';
--*px;
map[*px][*py]='o';
}
}
void move_2(char map[][20],int *px,int *py){
if(map[*px+1][*py]!='#'){
map[*px][*py]=' ';
++*px;
map[*px][*py]='o';
}
}
void move_3(char map[][20],int *px,int *py){
if(map[*px][*py-1]!='#'){
map[*px][*py]=' ';
--*py;
map[*px][*py]='o';
}
}
void move_4(char map[][20],int *px,int *py){
if(map[*px][*py+1]!='#'){
map[*px][*py]=' ';
++*py;
map[*px][*py]='o';
}
}

45 changes: 45 additions & 0 deletions level1/p09_maze/mapping.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#include "maze.h"
void mapping(){ //��ӡ�����ɵ��Թ�
char map[9][20]={{"# ##################"},
{"# # ## # "},
{"### ## ### # # ###"},
{"### # ## # ###"},
{"### # ## ## # ### #"},
{"# # ## ## ### ##"},
{"# # ## ### #### #"},
{"#### ## #"},
{"####################"}};
int x=0,y=1;
int *px=&x;
int *py=&y;

void cursor(){ //��� ���̷����
char c=getch();
switch(c){
case 72:move_1(map,px,py);
break;
case 80:move_2(map,px,py);
break;
case 75:move_3(map,px,py);
break;
case 77:move_4(map,px,py);
break;
default: break;
}
}


map[x][y]='o';
while(map[1][19]!='o'){
int i,j;
for(i=0;i<9;i++){
for(j=0;j<20;j++){
printf("%c",map[i][j]);
}
printf("\n");
}
cursor();
system("cls");
}

}
92 changes: 92 additions & 0 deletions level1/p09_maze/maze.dev
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
[Project]
FileName=maze.dev
Name=maze
Type=1
Ver=2
ObjFiles=
Includes=
Libs=
PrivateResource=
ResourceIncludes=
MakeIncludes=
Compiler=
CppCompiler=
Linker=
IsCpp=0
Icon=
ExeOutput=
ObjectOutput=
LogOutput=
LogOutputEnabled=0
OverrideOutput=0
OverrideOutputName=
HostApplication=
UseCustomMakefile=0
CustomMakefile=
CommandLine=
Folders=
IncludeVersionInfo=0
SupportXPThemes=0
CompilerSet=0
CompilerSettings=0000000000000000001000000
UnitCount=4

[VersionInfo]
Major=1
Minor=0
Release=0
Build=0
LanguageID=1033
CharsetID=1252
CompanyName=
FileVersion=
FileDescription=Developed using the Dev-C++ IDE
InternalName=
LegalCopyright=
LegalTrademarks=
OriginalFilename=
ProductName=
ProductVersion=
AutoIncBuildNr=0
SyncProduct=1

[Unit1]
FileName=mapping.c
CompileCpp=0
Folder=
Compile=1
Link=1
Priority=1000
OverrideBuildCmd=0
BuildCmd=

[Unit2]
FileName=maze.h
CompileCpp=0
Folder=
Compile=1
Link=1
Priority=1000
OverrideBuildCmd=0
BuildCmd=

[Unit3]
FileName=function.c
CompileCpp=0
Folder=
Compile=1
Link=1
Priority=1000
OverrideBuildCmd=0
BuildCmd=

[Unit4]
FileName=maze_main.c
CompileCpp=0
Folder=
Compile=1
Link=1
Priority=1000
OverrideBuildCmd=0
BuildCmd=

10 changes: 10 additions & 0 deletions level1/p09_maze/maze.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
void cursor();
void move_1(char (*)[20],int *px,int *py);
void move_2(char (*)[20],int *px,int *py);
void move_3(char (*)[20],int *px,int *py);
void move_4(char (*)[20],int *px,int *py);
void mapping();

6 changes: 6 additions & 0 deletions level1/p09_maze/maze_main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#include<stdio.h>
int main(){
mapping();
printf("well done");
return 0;
}
1 change: 1 addition & 0 deletions level1/p10_pushBoxes/level1_score.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
60
1 change: 1 addition & 0 deletions level1/p10_pushBoxes/level2_score.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
40
Loading