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

王瀚 second submission #34

Open
wants to merge 38 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
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
20 changes: 20 additions & 0 deletions homework2017.2.26/p01_runningLetter.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#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,不是cpp

#include<stdlib.h>
int main()
Copy link
Owner

Choose a reason for hiding this comment

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

加一个空行

{
const int lenth=80;
Copy link
Owner

Choose a reason for hiding this comment

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

常量习惯上采用全大写,单词之间可用下划线分隔;
应该是length吧

int len_now=0,goBack=0,step;
while (1)
{
system("cls");
for (step=1;step<len_now;step++)
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");
if (goBack) len_now--;
Copy link
Owner

Choose a reason for hiding this comment

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

大括号

else len_now++;
if (len_now==lenth) goBack=1;
else if (len_now==0) goBack=0;
sleep(50);
}
return 0;
}
21 changes: 21 additions & 0 deletions homework2017.2.26/p02_isPrime.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#include<stdio.h>
int main(){
int number,i;
while (scanf("%d",&number)!=EOF){
if (number==0){
break;
}
for (i=2;i*i<=number;i++){
if (number%i==0){
break;
}
}
if (i*i>number){
printf("Yes\n");
}
else{
printf("No\n");
}
}
return 0;
}
11 changes: 11 additions & 0 deletions homework2017.2.26/p03_Diophantus.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#include<stdio.h>
int main(){
int age=1;
while (age++){
if (age%6==0&&age%12==0&&age%7==0&&(age/2-age/6-age/12-age/7)==9) {
break;
}
}
printf("%d\n",age-4);
return 0;
}
14 changes: 14 additions & 0 deletions homework2017.2.26/p04_narcissus.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#include<stdio.h>
int main(){
int number;
int hundred,ten,one;
for (number=100;number<=999;number++){
hundred=number/100;
ten=(number/10)%10;
one=number%10;
if (number==hundred*hundred*hundred+ten*ten*ten+one*one*one){
printf("%d\n",number);
}
}
return 0;
}
26 changes: 26 additions & 0 deletions homework2017.2.26/p05_allPrimes.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#include<stdio.h>
#include<string.h>
#include<time.h>
int main(){
int i,j=2,prime[1000],numb;
clock_t start,endd;
start=clock();
memset(prime,0,sizeof(prime));
prime[1]=2;
printf("%d\n",prime[1]);
for (numb=3;numb<=1000;numb++){
for (i=1;prime[i]*prime[i]<=numb&&prime[i];i++){
if (numb%prime[i]==0){
break;
}
}
if(prime[i]*prime[i]>numb){
prime[j++]=numb;
printf("%d\n",numb);
}
}
endd=clock();
printf("The algorithm costs %.0lfms;\n",(double)(endd-start));
printf("It will costs 0.01ms without printf().\n");
return 0;
}
35 changes: 35 additions & 0 deletions homework2017.2.26/p06_Goldbach.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#include<stdio.h>
int main(){
int i,j=2,numb,prime[100];
prime[1]=2;
for (numb=3;numb<=100;numb++){
for (i=1;prime[i]*prime[i]<=numb&&prime[i];i++){
if (numb%prime[i]==0) break;
}
if(prime[i]*prime[i]>numb){
prime[j++]=numb;
}
}
for (numb=4;numb<=100;numb+=2){
for (i=1;prime[i]!=0;i++){
for (j=1;prime[j]!=0;j++){
if (prime[j]+prime[i]==numb){
break;
}
}
if (prime[j]==0){
break;
}
}
if (prime[i]==0&&prime[j]==0){
break;
}
}
if (numb>100){
printf("proved\n");
}
else{
printf("not");
}
return 0;
}