-
Notifications
You must be signed in to change notification settings - Fork 15
曹思瀚 #7
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
base: main
Are you sure you want to change the base?
曹思瀚 #7
Changes from 9 commits
618eed1
82cf1ac
8d7b549
287a8ff
b90f2d8
5275a44
2a14604
608aacd
5161018
c642361
dff403a
84a4544
64b8044
8650ed0
de8e148
eadbcc6
a2d4a4a
655c53f
0354832
e44cbac
2e63553
5bf93d8
f047706
0ffe103
ae80ff6
0ef935f
28cd146
61dc608
ffb83ee
e8f9674
8f2e10a
a5de514
1adb8f5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,60 @@ | ||
| #include <printf.h> | ||
| #include <stdio.h> | ||
| #include <windows.h> | ||
|
|
||
| #define RIGHT 00 | ||
| #define LEFT 1 | ||
|
|
||
|
|
||
| HANDLE hd; | ||
| int width,dir=RIGHT; | ||
| void move(int x,int y) | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 习惯上,我们只在前面写上函数原型,函数实现移到下面 |
||
| { | ||
| COORD pos={x,y}; | ||
| SetConsoleCursorPosition(hd,pos); | ||
| return; | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 这个return是多余的吧 |
||
| } | ||
| void GetSize() | ||
| { | ||
| CONSOLE_SCREEN_BUFFER_INFO info; | ||
| GetConsoleScreenBufferInfo(hd,&info); | ||
| width=info.srWindow.Right; | ||
| return; | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 同上 |
||
| } | ||
| int ne(int now) | ||
| { | ||
| if(dir==RIGHT) | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 感觉可以简化为一行,反而逻辑更清晰 |
||
| { | ||
| if(now!=width) return now+1; | ||
| else | ||
| { | ||
| dir=LEFT; | ||
| return now-1; | ||
| } | ||
| } | ||
| else | ||
| { | ||
| if(now) return now-1; | ||
| else | ||
| { | ||
| dir=RIGHT; | ||
| return now+1; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| int main() { | ||
| printf("hello world!\n"); | ||
| int now; | ||
| hd= GetStdHandle(STD_OUTPUT_HANDLE); | ||
| GetSize(); | ||
| printf("a"); | ||
| while(1) | ||
| { | ||
| move(now,0); | ||
| printf(" "); | ||
| now=ne(now); | ||
| move(now,0); | ||
| printf("a"); | ||
| Sleep(25); | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 幻数 |
||
| } | ||
| return 0; | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,27 @@ | ||
| #include <printf.h> | ||
|
|
||
| int main() { | ||
| printf("hello world!\n"); | ||
| #include<stdio.h> | ||
| int main() | ||
| { | ||
| int m,n; | ||
| int i; | ||
| int cnt=0; | ||
| int sum=0; | ||
| scanf("%d %d",&m,&n); | ||
| if(m==1){ | ||
| m=2;} | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 可以格式化一下 |
||
| for(i=m;i<=n;i++){ | ||
| int isprime=1; | ||
| int k; | ||
| for(k=2;k<i-1;k++){ | ||
| if(i%k==0){ | ||
| isprime=0; | ||
| break; | ||
| } | ||
| } | ||
| if(isprime){ | ||
| cnt++; | ||
| sum+=i; | ||
| } | ||
| } | ||
| printf("%d %d\n",cnt,sum); | ||
| return 0; | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,55 @@ | ||
| #include <printf.h> | ||
| #include <stdio.h> | ||
|
|
||
| int main() { | ||
| printf("hello world!\n"); | ||
| int i,x,cnt,num=0; | ||
| int a[100]; | ||
| for(i=2;i<=100;i++){ | ||
| cnt=0; | ||
| for(x=2;x<=i;x++){ | ||
| cnt++; | ||
| if(i%x==0){ | ||
| break; | ||
| } | ||
| } | ||
| if(cnt==i-1) { | ||
| printf("%d\n", i); | ||
| num++; | ||
| a[num-1]=i; | ||
| } | ||
| else | ||
| continue; | ||
| } | ||
| printf("num=%d\n",num); | ||
| int t,k,j,m,n,CNT=0; | ||
| for(t=6;t<=100;t++){ | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 感觉逻辑有点乱,不能一目了然 |
||
| // printf("%d->%d\n",t,CNT); | ||
| for(i=0;i<num;i++){ | ||
| if(a[i]<t){ | ||
| k=t-a[i]; | ||
| for(j=0;j<num;j++){ | ||
| m=k-a[j]; | ||
| for(n=0;n<num;n++){ | ||
| if(a[n]==m){ | ||
| CNT++; | ||
| goto end; | ||
| }else{ | ||
| continue; | ||
| } | ||
|
|
||
| } | ||
|
|
||
| } | ||
| } | ||
| else{ | ||
| break; | ||
| } | ||
| } | ||
| end:continue; | ||
| } | ||
| printf("CNT=%d\n",CNT); | ||
| if(CNT==95){ | ||
| printf("right"); | ||
| } | ||
|
|
||
| return 0; | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,55 @@ | ||
| #include <printf.h> | ||
| #include <stdio.h> | ||
|
|
||
| int main() { | ||
| printf("hello world!\n"); | ||
| int i,x,cnt,num=0; | ||
| int a[100]; | ||
| for(i=2;i<=100;i++){ | ||
| cnt=0; | ||
| for(x=2;x<=i;x++){ | ||
| cnt++; | ||
| if(i%x==0){ | ||
| break; | ||
| } | ||
| } | ||
| if(cnt==i-1) { | ||
| printf("%d\n", i); | ||
| num++; | ||
| a[num-1]=i; | ||
| } | ||
| else | ||
| continue; | ||
| } | ||
| printf("num=%d\n",num); | ||
| int t,k,j,m,n,CNT=0; | ||
| for(t=6;t<=100;t++){ | ||
| // printf("%d->%d\n",t,CNT); | ||
| for(i=0;i<num;i++){ | ||
| if(a[i]<t){ | ||
| k=t-a[i]; | ||
| for(j=0;j<num;j++){ | ||
| m=k-a[j]; | ||
| for(n=0;n<num;n++){ | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 嵌套太深 |
||
| if(a[n]==m){ | ||
| CNT++; | ||
| goto end; | ||
| }else{ | ||
| continue; | ||
| } | ||
|
|
||
| } | ||
|
|
||
| } | ||
| } | ||
| else{ | ||
| break; | ||
| } | ||
| } | ||
| end:continue; | ||
| } | ||
| printf("CNT=%d\n",CNT); | ||
| if(CNT==95){ | ||
| printf("right"); | ||
| } | ||
|
|
||
| return 0; | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,13 @@ | ||
| #include <printf.h> | ||
|
|
||
| int main() { | ||
| printf("hello world!\n"); | ||
| #include<stdio.h> | ||
| int main(){ | ||
| char a[26]; | ||
| a[0]='a'; | ||
| int i,x; | ||
| i=1; | ||
| while(i<26){ | ||
| a[i]=a[i-1]+1; | ||
| } | ||
| for(i=0;i<26;i++) | ||
| printf("%c",a[i]); | ||
| return 0; | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,28 @@ | ||
| #include <printf.h> | ||
| #include <stdio.h> | ||
|
|
||
| int main() { | ||
| printf("hello world!\n"); | ||
| return 0; | ||
| //定义move函数,将一个盘子从x座移到y座上 | ||
| void move(char x, char y) | ||
| { | ||
| printf("%c-->%c\n",x,y); //输出移盘方案。x,y代表A,B,C座之一,根据每次的不同情况分别取A,B,C代入 | ||
| } | ||
|
|
||
| void hanoi(int n, char one, char two, char three) //将n个盘从one座借助two座,移到three座 | ||
| { | ||
| if(n==1) | ||
| move(one, three); | ||
| else | ||
| { | ||
| hanoi(n-1, one, three, two); //将 A 座上 n-1 个盘子移到 B 座上(借助 C) | ||
| move(one, three);//将 A 座上剩下的 1 个盘子移到 C 座上 | ||
| hanoi(n-1, two, one, three);//将 B 座上 n-1 个盘子移到 C 座上(借助 A) | ||
| } | ||
| } | ||
|
|
||
| main() | ||
| { | ||
| int m; | ||
| printf("input the number of disks:"); | ||
| scanf("%d",&m); //盘子的数量 | ||
| printf("The step to moving %d disks:\n",m); | ||
| hanoi(m,'A','B','C'); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
为什么是00不是0呢?有什么特别的讲究吗?