diff --git "a/level1/p01_runningLetter/zuoye/\350\267\263\345\212\250\347\232\204\345\255\227\347\254\246.c" "b/level1/p01_runningLetter/zuoye/\350\267\263\345\212\250\347\232\204\345\255\227\347\254\246.c" new file mode 100644 index 00000000..0185a8d3 --- /dev/null +++ "b/level1/p01_runningLetter/zuoye/\350\267\263\345\212\250\347\232\204\345\255\227\347\254\246.c" @@ -0,0 +1,33 @@ +#include +#include +#include +int main() +{ + int i=0,j=1,m=0,k; + char words[20]; + scanf("%s",words); + k=strlen(words); // 取字符串长度 + system("mode con cols=100");//设定控制台宽度 + while(1) +{ + printf("%s",words); + system("cls"); //清屏 + for(i=0;i +#include +#include + +int main() +{ + int prime; + int i; + int j; + printf("璇疯緭鍏ヤ竴涓鏁存暟"); + scanf("%d",&prime); + if(prime==1) + { + printf("%d涓嶆槸绱犳暟\n",prime); + } + else + { + for(i=2;i<=prime-1;i++) + { + if( prime%i==0) + { + printf("%d涓嶆槸绱犳暟\n",prime); + return 0; + } + } + printf("%d鏄礌鏁癨n",prime); + } + system("pause"); + return 0; +} + diff --git "a/level1/p03_Diophantus/\344\270\242\347\225\252\345\233\276\345\271\264\351\276\204.cpp" "b/level1/p03_Diophantus/\344\270\242\347\225\252\345\233\276\345\271\264\351\276\204.cpp" new file mode 100644 index 00000000..066d1847 --- /dev/null +++ "b/level1/p03_Diophantus/\344\270\242\347\225\252\345\233\276\345\271\264\351\276\204.cpp" @@ -0,0 +1,21 @@ +#include +#include + +int main() +{ + double diufantu_age; + double d_son_age; + for(diufantu_age=12.0; ;diufantu_age++) + { + d_son_age=diufantu_age/2; + double sum=diufantu_age/6+diufantu_age/12+diufantu_age/7+5.0+4.0+d_son_age; + if(diufantu_age==sum) + { + break; + } + + + } + printf("diufantu's age is %-6.f",diufantu_age); + return 0; +} diff --git "a/level1/p04_ narcissus/\346\260\264\344\273\231\350\212\261\346\225\260.cpp" "b/level1/p04_ narcissus/\346\260\264\344\273\231\350\212\261\346\225\260.cpp" new file mode 100644 index 00000000..a21a4e74 --- /dev/null +++ "b/level1/p04_ narcissus/\346\260\264\344\273\231\350\212\261\346\225\260.cpp" @@ -0,0 +1,22 @@ +#include +#include + +int main() +{ + int n; + int a=0,b=0,c=0; + int sum; + for(n=100;n<1000;n++) + { + a=n/100; + b=n/10-n/100*10; + c=n/1-n/100*100-b*10; + sum=a*a*a+b*b*b+c*c*c; + if(sum==n) + { + printf("%d ",n); + } + } + return 0; +} + diff --git "a/level1/p05_allPrimes/\346\211\223\345\215\260all\347\264\240\346\225\260.cpp" "b/level1/p05_allPrimes/\346\211\223\345\215\260all\347\264\240\346\225\260.cpp" new file mode 100644 index 00000000..32ba0812 --- /dev/null +++ "b/level1/p05_allPrimes/\346\211\223\345\215\260all\347\264\240\346\225\260.cpp" @@ -0,0 +1,41 @@ +#include +#include +#include +#include + +bool judge(int prime) +{ + int i; + int j; + for(i=2;i<=(int)sqrt(prime);i++) + { + j=prime%i; + if(j==0) + { + return false; + } + } + return true; +} + +int main() +{ + int prime,clock1,clock2; + clock1=clock(); + for(prime=2;prime<1001;prime++) + { + if(prime==2) + { + printf(" %d ",prime); + } + + else if(judge(prime)) + { + printf(" %d ",prime); + } + } + clock2=clock(); + printf("时间是%d毫秒",clock2-clock1); + return 0; +} + diff --git "a/level1/p06_Goldbach/\345\223\245\345\276\267\345\267\264\350\265\253\347\214\234\346\203\263\347\232\204\346\255\243\347\241\256\346\200\247.cpp" "b/level1/p06_Goldbach/\345\223\245\345\276\267\345\267\264\350\265\253\347\214\234\346\203\263\347\232\204\346\255\243\347\241\256\346\200\247.cpp" new file mode 100644 index 00000000..13c9ccc7 --- /dev/null +++ "b/level1/p06_Goldbach/\345\223\245\345\276\267\345\267\264\350\265\253\347\214\234\346\203\263\347\232\204\346\255\243\347\241\256\346\200\247.cpp" @@ -0,0 +1,66 @@ +#include +#include +bool judge(int prime) +{ + int i; + for(i=2;i +#include +#include + +void jiami(char a[200]) +{ + for(int i=0;i<200;i++) + { + if(a[i]<='W'&&a[i]>='A') + { + a[i]=a[i]+3; + } + else if(a[i]>='X'&&a[i]<='Z') + { + a[i]=a[i]-23; + } + if(a[i]<='w'&&a[i]>='a') + { + a[i]=a[i]+3; + } + else if(a[i]>='x'&&a[i]<='z') + { + a[i]=a[i]-23; + } + } + printf("加密后是"); + puts(a); +} + +void jiemi(char b[200]) +{ + for(int i=0;i<200;i++) + { + if(b[i]<='Z'&&b[i]>='D') + { + b[i]=b[i]-3; + } + else if(b[i]<='C'&&b[i]>='A') + { + b[i]=b[i]+23; + } + if(b[i]<='z'&&b[i]>='d') + { + b[i]=b[i]-3; + } + else if(b[i]<='c'&&b[i]>='a') + { + b[i]=b[i]+23; + } + } + printf("解密后是"); + puts(b); +} + +int main() +{ + char mima[200]; + gets(mima); + jiami(mima); + jiemi(mima); + return 0; +} + + + + + + + + + + + + + + + + + + + + + + diff --git "a/level1/p08_hanoi/\346\261\211\350\257\272\345\241\224\351\227\256\351\242\230\347\232\204\351\200\222\345\275\222.cpp" "b/level1/p08_hanoi/\346\261\211\350\257\272\345\241\224\351\227\256\351\242\230\347\232\204\351\200\222\345\275\222.cpp" new file mode 100644 index 00000000..9126a7a0 --- /dev/null +++ "b/level1/p08_hanoi/\346\261\211\350\257\272\345\241\224\351\227\256\351\242\230\347\232\204\351\200\222\345\275\222.cpp" @@ -0,0 +1,28 @@ +#include +#include + +void function(int panzishu,char a,char b,char c) +{ + if(panzishu==1) + { + printf("灏%c===>%c\n",a,c); + } + else + { + function(panzishu-1,a,c,b); + printf("灏%c===>%c\n",a,c); + function(panzishu-1,b,a,c); + } +} +int main() +{ + int panzishu; + char a,b,c; + a='a'; + b='b'; + c='c'; + printf("璇疯緭鍏ユ眽璇哄鐨勭洏瀛愭暟閲:"); + scanf("%d",&panzishu); + function(panzishu,a,b,c); + return 0; +} diff --git a/level1/p09_maze/maze.cpp b/level1/p09_maze/maze.cpp new file mode 100644 index 00000000..550ca309 --- /dev/null +++ b/level1/p09_maze/maze.cpp @@ -0,0 +1,158 @@ +#include +#include +#include +int map[8][8]={{0,0,0,0,0,0,0,0}, + {2,4,4,4,4,0,0,1}, + {0,4,0,4,0,0,0,4}, + {0,4,0,4,4,4,0,4}, + {0,4,4,0,0,4,0,4}, + {0,4,0,4,0,4,0,4}, + {4,4,4,4,0,4,4,4}, + {0,0,0,0,0,0,0,0}}; + + + +void mapmaker() + { + for(int i=0;i<8;i++) + { + for(int j=0;j<8;j++) + { + switch(map[i][j]) + { + case 0: + printf("■"); + break; + case 1: + printf("☆"); + break; + case 2: + printf("♀"); + break; + case 4: + printf(" "); + break; + } + } + printf("\n"); + } + + } +void play() +{ //0代表墙,1代表正确地点,2代表人物 ,4代表空白区域 + char ch; + int m,n; + for(int i=0;i<8;i++) + { + for(int j=0;j<8;j++) + { + if(map[i][j]==2) + { + m=i; + n=j; + } + } + } + ch=getch(); + switch(ch) + { + case 'w': + case 'W': + if(map[m-1][n]==4) + { + map[m][n]=4; + map[m-1][n]=2; + } + else if(map[m-1][n]==1) + { + map[m][n]=4; + map[m-1][n]=2; + printf("you win\n"); + system("pause"); + } + break; + case 's': + case 'S': + if(map[m+1][n]==4) + { + map[m][n]=4; + map[m+1][n]=2; + } + else if(map[m-1][n]==1) + { + map[m][n]=4; + map[m-1][n]=2; + printf("you win\n"); + system("pause"); + } + break; + case 'a': + case 'A': + if(map[m][n-1]==4) + { + map[m][n]=4; + map[m][n-1]=2; + } + else if(map[m-1][n]==1) + { + map[m][n]=4; + map[m-1][n]=2; + printf("you win\n"); + system("pause"); + return; + } + break; + case 'd': + case 'D': + if(map[m][n+1]==4) + { + map[m][n]=4; + map[m][n+1]=2; + } + else if(map[m-1][n]==1) + { + map[m][n]=4; + map[m-1][n]=2; + printf("you win\n"); + system("pause"); + return; + } + break; + } + } + +int main() +{ + while(1) + { + system("cls"); + mapmaker(); + play(); + } + + return 0; +} + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/level1/p10_pushBoxes/map.txt b/level1/p10_pushBoxes/map.txt new file mode 100644 index 00000000..05ac15ea --- /dev/null +++ b/level1/p10_pushBoxes/map.txt @@ -0,0 +1,8 @@ +0 0 0 0 0 0 0 0 +2 4 4 4 4 0 0 1 +0 4 0 3 4 0 0 4 +0 4 4 4 4 0 0 4 +0 4 4 0 0 0 0 4 +4 4 0 4 0 4 4 4 +4 4 4 4 4 4 4 4 +0 0 0 0 0 0 4 4 diff --git "a/level1/p10_pushBoxes/\346\216\250\347\256\261\345\255\220\346\270\270\346\210\217.cpp" "b/level1/p10_pushBoxes/\346\216\250\347\256\261\345\255\220\346\270\270\346\210\217.cpp" new file mode 100644 index 00000000..69a7d4f6 --- /dev/null +++ "b/level1/p10_pushBoxes/\346\216\250\347\256\261\345\255\220\346\270\270\346\210\217.cpp" @@ -0,0 +1,283 @@ +#include +#include +#include +#include +int map[8][8]; +int step=0; + +FILE *fpRead=fopen("map.txt","r"); + +void mapmaker() + { + for(int i=0;i<8;i++) + { + for(int j=0;j<8;j++) + { + switch(map[i][j]) + { + case 0: + printf("鈻"); + break; + case 1: + printf("鈽"); + break; + case 2: + printf("鈾"); + break; + case 3: + printf("鈻"); + break; + case 4: + printf(" "); + break; + default: + printf("error"); + } + } + printf("\n"); + } + printf("your step is "); + + } +void play() +{ //0浠h〃澧欙紝1浠h〃姝g‘鍦扮偣锛2浠h〃浜虹墿锛3浠h〃绠卞瓙 ,4浠h〃绌虹櫧鍖哄煙 + int m,n; + int k,l; + int over=0; + for(int i=0;i<8;i++) + { + for(int j=0;j<8;j++) + { + if(map[i][j]==2) + { + m=i; + n=j; + } + if(map[i][j]==3) + { + k=i; + l=j; + } + if(map[i][j]==1) + { + over++; + } + } + } + if(over==0) + { + printf("%d\n",step); + printf("you win\n"); + system("pause"); + return; + } + + + char ch; + ch=getch(); + printf("%d\n",step); + switch(ch) + { + case 'w': + case 'W': + step++; + if(map[m-1][n]==4) + { + map[m][n]=4; + map[m-1][n]=2; + } + if(map[m-1][n]==3) + { + if(map[k-1][l]!=1) + { + map[k][l]=4; + map[k-1][l]=3; + map[m][n]=4; + map[m-1][n]=2; + } + else if(map[k-1][l]==1&&map[k][l]!=1) + { + map[k][l]=4; + map[k-1][l]=3; + map[m][n]=4; + map[m-1][n]=2; + } + else if(map[k-1][l]==1&&map[k][l]==1) + { + map[k][l]=1; + map[k-1][l]=3; + map[m][n]=4; + map[m-1][n]=2; + } + } + if(map[m-1][n]==0) + { + map[m-1][n]=0; + map[m][n]=2; + } + break; + case 's': + case 'S': + step++; + if(map[m+1][n]==4) + { + map[m][n]=4; + map[m+1][n]=2; + } + if(map[m+1][n]==3) + { + if(map[k+1][l]!=1) + { + map[k][l]=4; + map[k+1][l]=3; + map[m][n]=4; + map[m+1][n]=2; + } + else if(map[k+1][l]==1&&map[k][l]!=1) + { + map[k][l]=4; + map[k+1][l]=3; + map[m][n]=4; + map[m+1][n]=2; + } + else if(map[k+1][l]==1&&map[k][l]==1) + { + map[k][l]=1; + map[k+1][l]=3; + map[m][n]=4; + map[m+1][n]=2; + } + + } + break; + case 'a': + case 'A': + step++; + if(map[m][n-1]==4) + { + + map[m][n]=4; + map[m][n-1]=2; + } + if(map[m][n-1]==3) + { + if(map[k][l-1]!=1) + { + map[k][l]=4; + map[k][l-1]=3; + map[m][n]=4; + map[m][n-1]=2; + } + else if(map[k][l-1]==1&&map[k][l]!=1) + { + map[k][l]=4; + map[k][l-1]=3; + map[m][n]=4; + map[m][n-1]=2; + } + else if(map[k][l-1]==1&&map[k][l]==1) + { + map[k][l]=1; + map[k][l-1]=3; + map[m][n]=4; + map[m][n-1]=2; + } + + } + break; + case 'd': + case 'D': + step++; + if(map[m][n+1]==4) + { + map[m][n]=4; + map[m][n+1]=2; + } + if(map[m][n+1]==3) + { + if(map[k][l+1]!=1) + { + map[k][l]=4; + map[k][l+1]=3; + map[m][n]=4; + map[m][n+1]=2; + } + if(map[k][l+1]==1&&map[k][l]!=1) + { + map[k][l]=4; + map[k][l+1]=3; + map[m][n]=4; + map[m][n+1]=2; + } + if(map[k][l+1]==1&&map[k][l]==1) + { + map[k][l]=1; + map[k][l+1]=3; + map[m][n]=4; + map[m][n+1]=2; + } + } + break; + default: + printf("error\n"); + } + + } + + +int main() +{ + while(1) + { + + if(fpRead==NULL) + { + return 0; + } + for(int i=0;i<8;i++) + { + for(int j=0;j<8;j++) + { + fscanf(fpRead,"%d",&map[i][j]); + } + } + system("cls"); + mapmaker(); + play(); + + + +} + return 0; +} + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git "a/level1/p11_linkedList/\351\223\276\350\241\250.cpp" "b/level1/p11_linkedList/\351\223\276\350\241\250.cpp" new file mode 100644 index 00000000..e3dc8edd --- /dev/null +++ "b/level1/p11_linkedList/\351\223\276\350\241\250.cpp" @@ -0,0 +1,101 @@ +#include +#include + + +typedef struct LNode +{ + int value; + struct LNode *next; +}LNode,*linkList; + +linkList creatLinkList(int n) +{ + linkList head = (linkList)malloc(sizeof(LNode)); + linkList p,q; + head->value=n; + q = head; + for(int i = 0;i < n;i++) { + p = (linkList)malloc(sizeof(LNode)); + scanf("%d",&p->value); + q->next = p; + q = p; + } + q->next = NULL; + return head; +} + +void listTraverse(linkList q) +{ + while(q->next) { + printf("%d ",q->next->value); + q = q->next; + } +} + +linkList reverseLinkList(linkList head) +{ + linkList q= head->next,p = NULL; + head->next = NULL; + while(q) + { + head->value=q->value; + p = q->next; + q->next = head; + head= q; + q = p; + } + return head; +} + +linkList search(linkList head,int n) +{ + linkList q=head->next; + int m; + m=n; + while(q) + { + + if(q->value==5) + { + printf("%d ",m); + m--; + } + if(q->value!=5) + { + m--; + printf("-1 "); + } + q=q->next; + } +} + +int main() { + int n; + printf("链表节点个数:"); + scanf("%d\n",&n); + linkList head = creatLinkList(n); + printf("创建后遍历:\n"); + listTraverse(head); + printf("\n单链表转置后:\n"); + head = reverseLinkList(head); + listTraverse(head); + printf("\n"); + printf("节点为5返回所在序号,否则返回-1\n"); + search(head,n); +} + + + + + + + + + + + + + + + + diff --git a/level1/p12_warehouse/information.txt b/level1/p12_warehouse/information.txt new file mode 100644 index 00000000..0e4a5b2c --- /dev/null +++ b/level1/p12_warehouse/information.txt @@ -0,0 +1 @@ +0s 1s 2s 2s 3s 3s 4s 4s 5s 5s \ No newline at end of file diff --git "a/level1/p12_warehouse/\344\273\223\345\272\223\346\234\200\347\273\210\347\211\210.cpp" "b/level1/p12_warehouse/\344\273\223\345\272\223\346\234\200\347\273\210\347\211\210.cpp" new file mode 100644 index 00000000..3f6bfcf3 --- /dev/null +++ "b/level1/p12_warehouse/\344\273\223\345\272\223\346\234\200\347\273\210\347\211\210.cpp" @@ -0,0 +1,289 @@ +#include +#include +#include +#include +#define n 10 + +char xing[100]; +int num[100]; +void caidan(void); + + +typedef struct xinxi +{ + char xinghao; + int number; + int bianhao; + struct xinxi *next; +}xinxi,*XINXI; + +XINXI p; + + + +XINXI list(XINXI p) +{ + XINXI q; + XINXI head; + head=p=(XINXI)malloc(sizeof(xinxi)); + for(int i=0;inext=q; + p->bianhao=i+1; + p->number=num[i]; + p->xinghao=xing[i]; + p=p->next; + } + p->next=NULL; + return head; +} + +void current(XINXI p) +{ + char ss=' '; + FILE *fp=fopen("information.txt","r"); + int m,k; + m=1; + XINXI elem=list(p); + while(m!=0) + { + printf("请输入要入库的货物编号以及数量(输入0 0停止入库)\n"); + scanf("%d %d",&m,&k); + if(m==0&&k==0) + { + system("cls"); + fp=fopen("information.txt","w"); + for(int i=0;ibianhao==m) + { + elem->number=elem->number+k; + num[m-1]=num[m-1]+k; + printf("成功入库!剩余库存%d\n",elem->number); + printf("按任意键继续\n"); + getch(); + system("cls"); + continue; + + } + else if(elem->bianhao!=m) + { + elem=elem->next; + while(elem!=NULL) + { + + if(elem->bianhao==m) + { + elem->number=elem->number+k; + num[m-1]=num[m-1]+k; + printf("成功入库!剩余库存%d\n",elem->number); + printf("按任意键继续\n"); + getch(); + system("cls"); + break; + } + } + } + fp=fopen("information.txt","w"); + for(int i=0;ibianhao==m) + { + if(elem->number-k>=0) + { + elem->number=elem->number-k; + num[m-1]=num[m-1]-k; + printf("成功出库!剩余库存%d\n",elem->number); + printf("按任意键继续\n"); + getch(); + system("cls"); + continue; + } + else + { + printf("库存不足!出库失败!\n"); + printf("按任意键继续\n"); + getch(); + system("cls"); + continue; + } + + } + else + { + while(elem!=NULL) + { + elem=elem->next; + if(elem->bianhao==m) + { + if(elem->number-k>=0) + { + elem->number=elem->number-k; + num[m-1]=num[m-1]-k; + printf("成功出库!剩余库存%d\n",elem->number); + printf("按任意键继续\n"); + getch(); + system("cls"); + break; + } + else + { + printf("库存不足!出库失败!\n"); + printf("按任意键继续\n"); + getch(); + system("cls"); + break; + } + } + } + } + fp=fopen("information.txt","w"); + for(int i=0;i显示存货列表 ###########\n"); + printf("####### 3 ->入库 ###########\n"); + printf("####### 4 ->出库 ###########\n"); + printf("####### 5 ->退出程序 并保存库存信息 #####\n"); + char ch; + char gh; + char c[100]; + char ss=' '; + int k=0; + FILE *fp=fopen("information.txt","r"); + FILE *fpRead=fopen("information.txt","r"); + if(fpRead!=NULL) + { + for(int i=0;i<1000;i++) + { + fscanf(fpRead,"%d%c",&num[i],&xing[i]); + } + } + ch=getch(); + switch(ch) + { + case '2': + system("cls"); + + while(fscanf(fp,"%c",&c[k])!=EOF) + { + printf("%c",c[k]); + k++; + } + + printf("\n"); + printf("按5返回至主界面\n"); + + gh=getch(); + if(gh==5); + { + system("cls"); + caidan(); + } + break; + case '3': + current(p); + printf("\n"); + printf("按5返回至主界面\n"); + gh=getch(); + if(gh==5); + { + system("cls"); + caidan(); + } + + break; + case '4': + output(p); + printf("\n"); + printf("按5返回至主界面\n"); + gh=getch(); + if(gh==5); + { + system("cls"); + caidan(); + } + + break; + case '5': + fp=fopen("information.txt","w"); + for(int i=0;i