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

作业 #15

Open
wants to merge 26 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
40 changes: 40 additions & 0 deletions level1/p01_runningLetter/runningLetter.cpp
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)
Copy link
Owner

Choose a reason for hiding this comment

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

重复的味道,试着消除吧

{
printf(" ");
}
printf("p");
Sleep(20);
system("cls");
--i;
}
}
}
29 changes: 29 additions & 0 deletions level1/p02_isPrime/isPrime.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#include <stdio.h>

bool isPrime(int num)
{
if(num==1)
{
return false;
}
for(int i =2;i*i<=num;i++)
{
if(num%i==0)return false;
}
return true;
}

int main()
{
int n = 0;
scanf("%d", &n);
if (isPrime(n))
{
printf("%d是素数", n);
}
else
{
printf("%d不是素数", n);
}

}
16 changes: 16 additions & 0 deletions level1/p03_Diophantus/Diophantus.cpp
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;
}
2 changes: 1 addition & 1 deletion level1/p03_Diophantus/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@

儿子比父亲先死四年,

年级是他的一半
年纪是他的一半

问儿子死时丢番图多大?
19 changes: 19 additions & 0 deletions level1/p04_ narcissus/narcissus.cpp
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;
}
30 changes: 30 additions & 0 deletions level1/p05_allPrimes/allPrime.cpp
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);
}
59 changes: 59 additions & 0 deletions level1/p06_Goldbach/Goldbach.cpp
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��Χ�ڲ�����ȷ��");
}
}
46 changes: 46 additions & 0 deletions level1/p07_encrypt_decrypt/encrypt_decrypt.cpp
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);
}
22 changes: 22 additions & 0 deletions level1/p08_hanoi/hanoi.cpp
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);
}
99 changes: 99 additions & 0 deletions level1/p09_maze/迷宫.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
#include<iostream>
#include<conio.h>
#include<windows.h>
using namespace std;
HANDLE hOut;

char cursorCharRead()
{
char buf[BUFSIZ];
CONSOLE_SCREEN_BUFFER_INFO csbiInfo;
HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
GetConsoleScreenBufferInfo(hConsole, &csbiInfo);
COORD pos = csbiInfo.dwCursorPosition;
TCHAR strFromConsole[1];
DWORD dwChars;
ReadConsoleOutputCharacter(hConsole,strFromConsole,1,pos,&dwChars);
char c = strFromConsole[0];
return c;
}

int main()
{
printf("******************* *********************\n");
printf("* * * * * * * *\n");
printf("* * ******* * * * * ***** * * ***** * * *\n");
printf("* * * * * * * * * * * * *\n");
printf("******* ***** * * ***** *** ***** * * * *\n");
printf("* * * * * * * * * * *\n");
printf("* * * *** * *** *** * *** ***** ***** * *\n");
printf("* * * * * * * * * *\n");
printf("* * *** ************* * ***** ***** *** *\n");
printf("* * * * * * * * * * * * * *\n");
printf("* *** ******* * * * ***** * * * * *** * *\n");
printf("* * * * * * * * * * * *\n");
printf("* * ********* ***** * * *** * * ***** * *\n");
printf("* * * * * * * * * * * * * *\n");
printf("* * * * * *** * * *** * * ***** * * *****\n");
printf("* * * * * * * * * * * * * *\n");
printf("* ***** * * *** *** *** ***** * * ***** *\n");
printf("* * * * * * * * * * *\n");
printf("* ******* *** *** *** * *** *** ***** * *\n");
printf("* * * * * * * * * * * * *\n");
printf("* * *** * * *** *** ***** *** * *** *** *\n");
printf("* * * * * * * * * * *\n");
printf("* * * * ***** * ***** * ********* * *****\n");
printf("* * * * * * * * *\n");
printf("* * ******* ***** * *** * *** *** *** * *\n");
printf("* * * * * * * * * * * *\n");
printf("* ***** *** * ******* ***** *** * * *****\n");
printf("* * * * * * * * * *\n");
printf("********* ******* * ***** * * * *** *** *\n");
printf("* * * * * * * * * * * *\n");
printf("***** * *** *** *** * * ******* * *** * *\n");
printf("* * * * * * * * * * * *\n");
printf("* * *** * *** ***** ***** * * * * * * ***\n");
printf("* * * * * * * * * * * *\n");
printf("* *** ***** * * * * * * *** *********** *\n");
printf("* * * * * * * * * * * *\n");
printf("******* * * ***** ******* *** ******* * *\n");
printf("* * * * * * * * * *\n");
printf("* ***** *** * * ***** * *** *** * *** * *\n");
printf("* * * * * * * * *\n");
printf("********************* *******************\n");
HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE);
COORD w = { 21, 40 };
SetConsoleCursorPosition(hOut, w);
while (w.X != 19 || w.Y != 0)
{
int ch1 = 0, ch2 = 0;
int t = 0;
if (ch1 = getch())
{
ch2 = getch();
switch (ch2)
{
case 72:w.Y--; t = 1; break;
case 80:w.Y++; t = 2; break;
case 75:w.X--; t = 3; break;
case 77:w.X++; t = 4; break;
}
}
SetConsoleCursorPosition(hOut, w);
if (cursorCharRead() == '*')
{
switch (t)
{
case 1:w.Y++; break;
case 2:w.Y--; break;
case 3:w.X++; break;
case 4:w.X--; break;
}
}
SetConsoleCursorPosition(hOut, w);
}
w.X = 0;
w.Y = 41;
SetConsoleCursorPosition(hOut, w);
printf("恭喜过关!");
}
8 changes: 8 additions & 0 deletions level1/p10_pushBoxes/1.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
0 0 3 3 3 3 0 0
0 0 3 2 2 3 0 0
0 3 3 0 2 3 3 0
0 3 0 0 4 2 3 0
3 3 0 4 0 0 3 3
3 0 0 3 4 4 0 3
3 0 0 1 0 0 0 3
3 3 3 3 3 3 3 3
Loading