-
Notifications
You must be signed in to change notification settings - Fork 33
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
作业 #15
base: master
Are you sure you want to change the base?
作业 #15
Changes from 9 commits
99bdb64
8a2db4d
5673898
03705b5
31de5e3
3cc3560
869e547
46ae883
77dd71d
c2ce2d5
61021ac
5e99c36
9c0b542
0915592
4245937
8cfe063
ace955c
d5f48ee
3f57ebc
361366c
e7c9ae4
a943c66
efc6810
8bd3f79
afacf9c
cf5694a
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 |
---|---|---|
@@ -0,0 +1,40 @@ | ||
#include <stdio.h> | ||
#include <windows.h> | ||
|
||
int GetWidth() | ||
{ | ||
CONSOLE_SCREEN_BUFFER_INFO scr; | ||
HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE); | ||
GetConsoleScreenBufferInfo(hOut, &scr); | ||
return scr.dwMaximumWindowSize.X; | ||
} | ||
|
||
int main() | ||
{ | ||
int i = 0, width = GetWidth(); | ||
while (1) | ||
{ | ||
while (i <= width-2) | ||
{ | ||
for (int j = 0; j < i; ++j) | ||
{ | ||
printf(" "); | ||
} | ||
printf("p"); | ||
Sleep(20); | ||
system("cls"); | ||
++i; | ||
} | ||
while (i >= 0) | ||
{ | ||
for (int j = 0; j < i; ++j) | ||
{ | ||
printf(" "); | ||
} | ||
printf("p"); | ||
Sleep(20); | ||
system("cls"); | ||
--i; | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
#include <stdio.h> | ||
|
||
int main() | ||
{ | ||
int n = 0; | ||
scanf_s("%d", &n); | ||
int Isprime = 1; | ||
for (int j = 2; j <= n / 2; j++) | ||
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 (n % j == 0) | ||
{ | ||
Isprime = 0; | ||
break; | ||
} | ||
} | ||
if (n == 1) | ||
{ | ||
printf("%d��������", n); | ||
} | ||
else | ||
{ | ||
if (Isprime == 1) | ||
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 (IsPrime) 更像老手一点 |
||
{ | ||
printf("%d������", n); | ||
} | ||
if (Isprime == 0) | ||
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. 可以改为 else |
||
{ | ||
printf("%d��������", n); | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#include<stdio.h> | ||
|
||
int main() | ||
{ | ||
float Diophantus_age = 1; | ||
for (Diophantus_age = 1; 1; Diophantus_age++) | ||
{ | ||
|
||
if (Diophantus_age / 12 + Diophantus_age / 6 + Diophantus_age / 7 + 5 + Diophantus_age / 2 + 4 == Diophantus_age) | ||
{ | ||
break; | ||
} | ||
} | ||
printf("%d", (int)Diophantus_age-4); | ||
return 0; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,6 +12,6 @@ | |
|
||
儿子比父亲先死四年, | ||
|
||
年级是他的一半。 | ||
年纪是他的一半。 | ||
|
||
问儿子死时丢番图多大? |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
#include<stdio.h> | ||
|
||
int main() | ||
{ | ||
for (int i = 1; i < 10; i++) | ||
{ | ||
for (int j = 0; j < 10; j++) | ||
{ | ||
for (int k = 0; k < 10; k++) | ||
{ | ||
if (i * i * i + j * j * j + k * k * k == 100 * i + 10 * j + k) | ||
{ | ||
printf("%d\n", 100 * i + 10 * j + k); | ||
} | ||
} | ||
} | ||
} | ||
return 0; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
#include <stdio.h> | ||
#include <time.h> | ||
|
||
int main() | ||
{ | ||
int i = 2; | ||
int IsPrime = 1; | ||
clock_t start, finish; | ||
double Total_time; | ||
start = clock(); | ||
for (i = 2; i <= 1000; i++) | ||
{ | ||
IsPrime = 1; | ||
for (int j = 2; j <= i / 2; j++) | ||
{ | ||
if (i % j == 0) | ||
{ | ||
IsPrime = 0; | ||
break; | ||
} | ||
} | ||
if (IsPrime == 1) | ||
{ | ||
printf("%d\n", i); | ||
} | ||
} | ||
finish = clock(); | ||
Total_time = (double)(finish - start) / CLOCKS_PER_SEC; | ||
printf("%f seconds\n", Total_time); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
#include<stdio.h> | ||
|
||
int main() | ||
{ | ||
int i = 2; | ||
int IsPrime = 1; | ||
int a[50] = { 0 }; | ||
int k = 0; | ||
for (i = 2; i <= 100; i++) | ||
{ | ||
IsPrime = 1; | ||
for (int j = 2; j <= i / 2; j++) | ||
{ | ||
if (i % j == 0) | ||
{ | ||
IsPrime = 0; | ||
break; | ||
} | ||
} | ||
if (IsPrime == 1) | ||
{ | ||
a[k] = i; | ||
k++; | ||
} | ||
} | ||
int sum = 0; | ||
int h = 4; | ||
for (h = 4; h <= 100; h = h + 2) | ||
{ | ||
int s = 1; | ||
for (int x = 0; x < k; x++) | ||
{ | ||
for (int y = 0; y <= x; y++) | ||
{ | ||
if (a[x] + a[y] == h) | ||
{ | ||
s = 0; | ||
break; | ||
} | ||
} | ||
if (s == 0) | ||
{ | ||
break; | ||
} | ||
} | ||
if (s == 0) | ||
{ | ||
sum++; | ||
} | ||
} | ||
if (sum == 49) | ||
{ | ||
printf("��°ͺղ�����100��Χ������ȷ��"); | ||
} | ||
else | ||
{ | ||
printf("��°ͺղ�����100��Χ�ڲ�����ȷ��"); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
#include <stdio.h> | ||
#include <string.h> | ||
#include <iostream> | ||
|
||
void encrypt(char* source, char* encrypted) | ||
{ | ||
while (*source != '\0') | ||
{ | ||
*encrypted = 158 - *source; | ||
source++; | ||
encrypted++; | ||
} | ||
} | ||
|
||
void decrypt(char* encrypted, char* source) | ||
{ | ||
while (*encrypted != '\0') | ||
{ | ||
*source = 158 - *encrypted; | ||
source++; | ||
encrypted++; | ||
} | ||
} | ||
|
||
int main() | ||
{ | ||
printf("��������Ҫ�����ַ����ij��ȣ�"); | ||
int n = 0; | ||
std::cin >> n; | ||
char* a = new char[n + 1](); | ||
char* b = new char[n + 1](); | ||
scanf("%s", a); | ||
encrypt(a, b); | ||
printf("���ܺ���ַ���Ϊ��"); | ||
printf("%s\n", b); | ||
printf("��������Ҫ���ܵ��ַ����ij��ȣ�"); | ||
int s = 0; | ||
scanf("%d", &s); | ||
char* c = new char[n + 1](); | ||
char* d = new char[n + 1](); | ||
printf("��Ҫ���ܵ��ַ���Ϊ��"); | ||
scanf("%s", c); | ||
decrypt(c, d); | ||
printf("���ܺ���ַ���Ϊ��"); | ||
printf("%s", d); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#include<iostream> | ||
|
||
void hanoi(int n, char a, char b, char c) | ||
{ | ||
if (n == 1) | ||
{ | ||
printf("��Բ��%d��%c�Ƶ�%c", n, a, c); | ||
} | ||
else | ||
{ | ||
hanoi(n - 1, a, c, b); | ||
printf("��Բ��%d��%c�Ƶ�%c", n, a, c); | ||
hanoi(n - 1, b, a, c); | ||
} | ||
} | ||
int main() | ||
{ | ||
char A = 'A'; | ||
char B = 'B'; | ||
char C = 'C'; | ||
hanoi(64, 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.
重复的味道,试着消除吧