Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
c649b70
Chen Nanxi
chennx31424 Sep 12, 2023
22dc2f8
commit homework
chennx31424 Sep 12, 2023
6329154
commit homework
chennx31424 Sep 12, 2023
7a45b1d
commit homework
chennx31424 Sep 12, 2023
b94110d
Update main.c
chennx31424 Sep 15, 2023
6ddc9c5
Update and rename main.c to main.cpp
chennx31424 Sep 16, 2023
8200f26
Update main.c
chennx31424 Sep 19, 2023
a8ed51f
Chen Nanxi
chennx31424 Sep 23, 2023
3a1332b
Chen Nanxi
chennx31424 Sep 26, 2023
c678570
Update main.c
chennx31424 Sep 26, 2023
ac0b95c
Chen Nanxi
chennx31424 Oct 6, 2023
4af3066
Create maze.c
chennx31424 Oct 6, 2023
ef5fa43
Create maze.h
chennx31424 Oct 6, 2023
12f8024
Update main.c
chennx31424 Oct 6, 2023
fc09acf
Chen Nanxi
chennx31424 Oct 9, 2023
a6b0eb7
Add files via upload
chennx31424 Oct 9, 2023
6004cb3
Update main.c
chennx31424 Oct 9, 2023
4a522ca
Add files via upload
chennx31424 Oct 9, 2023
0ef8079
Update CMakeLists.txt
chennx31424 Oct 9, 2023
aaf1a12
Chen Nanxi
chennx31424 Oct 15, 2023
a7cac6e
Merge remote-tracking branch 'origin/main'
chennx31424 Oct 15, 2023
1f23c7e
Chen Nanxi
chennx31424 Oct 15, 2023
3af5811
Update main.c
chennx31424 Oct 15, 2023
b4748eb
Update maze.c
chennx31424 Oct 15, 2023
9549a5c
Update maze.h
chennx31424 Oct 15, 2023
4978048
Chen Nanxi
chennx31424 Oct 19, 2023
b553fba
Merge remote-tracking branch 'origin/main'
chennx31424 Oct 19, 2023
19ff469
Update warehouse.txt
chennx31424 Oct 19, 2023
470d94b
五子棋AI实验报告
chennx31424 Dec 22, 2023
55fc63e
Add files via upload
chennx31424 Jan 4, 2024
58d47ac
Add files via upload
chennx31424 Jan 4, 2024
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
15 changes: 8 additions & 7 deletions level1/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,21 @@ project(level1)

add_executable(p01_running_letter p01_running_letter/main.c)

add_executable(p02_is_prime p02_is_prime/main.c)
add_executable(p02_is_prime p02_is_prime/main.c p02_is_prime/prime.c)

add_executable(p03_all_primes p03_all_primes/main.c)
add_executable(p03_all_primes p03_all_primes/main.c p03_all_primes/prime.c)

add_executable(p04_goldbach p04_goldbach/main.c)

add_executable(p05_encrypt_decrypt p05_encrypt_decrypt/main.c)

add_executable(p06_hanoi p06_hanoi/main.c)
add_executable(p06_hanoi p06_hanoi/main.cpp)

add_executable(p07_maze p07_maze/main.c)
add_executable(p07_maze p07_maze/main.c p07_maze/maze.c)

add_executable(p08_push_boxes p08_push_boxes/main.c)
add_executable(p08_push_boxes p08_push_boxes/main.c p08_push_boxes/push_boxes.c)

add_executable(p09_linked_list p09_linked_list/main.c)
add_executable(p09_linked_list p09_linked_list/main.c p09_linked_list/linked.c)

add_executable(p10_warehouse p10_warehouse/main.c)
add_executable(p10_warehouse p10_warehouse/main.c
p10_warehouse/warehouse.c)
32 changes: 27 additions & 5 deletions level1/p01_running_letter/main.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,28 @@
#include <printf.h>

int main() {
printf("hello world!\n");
#include <stdio.h>
#include <windows.h>
int main()
{ while(1)
{
for (int i = 0; i < 82; i++)
{
for (int j = 0; j < i; j++)
{
printf(" ");
}
printf("word");
Sleep(50);
system("cls");
}
for (int i = 82; i > 0; i--)
{
for (int j = 0; j < i; j++)
{
printf(" ");
}
printf("word");
Sleep(50);
system("cls");
}
}
return 0;
}
}
29 changes: 24 additions & 5 deletions level1/p02_is_prime/main.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,25 @@
#include <printf.h>

int main() {
printf("hello world!\n");
#include <stdio.h>
#include <math.h>
int Exam(int n)
{ int i = 0;
for(i = 2;i<=floor(sqrt(n));i++)
{
if(n%i==0)
break;
}
if(i==floor(sqrt(n)+1))
return 1;
else
return 0;
}
int main()
{ setbuf(stdout,NULL);
int num = 0;
printf("Please input a number:");
scanf("%d", &num);
if (Exam(num))
printf("The number is prime number\n");
else
printf("The number is not prime number\n");
return 0;
}
}
27 changes: 22 additions & 5 deletions level1/p03_all_primes/main.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,23 @@
#include <printf.h>

int main() {
printf("hello world!\n");
#include <stdio.h>
#include <math.h>
int Exam(int n)
{ int i = 0;
for(i = 2;i<=floor(sqrt(n));i++)
{
if(n%i==0)
break;
}
if(i==floor(sqrt(n)+1))
return 1;
else
return 0;
}
int main()
{ setbuf(stdout,NULL);
for(int i = 0;i<1001;i++)
{
if(Exam(i))
printf("%3d ",i);
}
return 0;
}
}
57 changes: 52 additions & 5 deletions level1/p04_goldbach/main.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,53 @@
#include <printf.h>
#include <stdio.h>
#include <math.h>
#define num 100
int Exam(int n)
{ int i = 0;
for(i = 2;i<=floor(sqrt(n));i++)
{
if(n%i==0)
break;
}
if(i==floor(sqrt(n)+1))
return 1;
else
return 0;
}
int main()
{ int count = 0;
for(int i = 2,j = 0;i<num + 1;i++)
{if(Exam(i))
count++;
}
int arr[count];
for(int i = 2,j = 0;i<num + 1;i++)
{ if(Exam(i))
{
arr[j]=i;
j++;
}
}
int test = 0;
for(int i = 4;i<num + 1;i+=2)
{
for (int m = 0,n = 0; m < count; m++)
{
for (n = 0; n < count; n++)
{
if (arr[m] + arr[n] == i)
{
printf("%d=%d+%d\n", i, arr[m], arr[n]);
test++;
break;
}
}
if(arr[m]+arr[n]==i)
break;
}
}
if(test==(num - 2)/2)
printf("Goldbach conjecture is right within 100");
else
printf("Goldbach conjecture is not right within 100");
return 0;}

int main() {
printf("hello world!\n");
return 0;
}
95 changes: 91 additions & 4 deletions level1/p05_encrypt_decrypt/main.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,93 @@
#include <printf.h>
#include <stdio.h>
#include <string.h>

int main() {
printf("hello world!\n");
void Enc(char* str, int shift)
{ int len = strlen(str);
for (int i = 0; i < len; i++)
{
if (str[i] >= 'a' && str[i] <= 'z')
{
str[i] = (str[i] - 'a' + shift) % 26 + 'a';
}
else if (str[i] >= 'A' && str[i] <= 'Z')
{
str[i] = (str[i] - 'A' + shift) % 26 + 'A';
}
}
char copy[100];
for(int i = 0;i<len;i++)
{
copy[i]=str[i];
}
for(int i = 0;i<len;i++)
{
str[i]=copy[len - 1 - i];
}
}
void Dec(char *str, int shift)
{
int len = strlen(str);
for (int i = 0; i < len; i++)
{
if (str[i] >= 'a' && str[i] <= 'z')
{
str[i] = (str[i] - 'a' - shift + 26) % 26 + 'a';
}
else if (str[i] >= 'A' && str[i] <= 'Z')
{
str[i] = (str[i] - 'A' - shift + 26) % 26 + 'A';
}
}
char copy[100];
for(int i = 0;i<len;i++)
{
copy[i]=str[i];
}
for(int i = 0;i<len;i++)
{
str[i]=copy[len - 1 - i];
}
}

int main()
{ setbuf(stdout,NULL);
int shift = 0;
flag:
printf("Enter a shift(shift>0):");
scanf("%d", &shift);
if(shift<=0)
{
printf("ERROR\n");
goto flag;
}
while(1)
{
int input = 0;
arrow:
printf("Please choose:\n1.Encrypt\n2.Decrypt\n3.Exit\n");
scanf("%d", &input);
char str1[1000], str2[1000];
if (input == 1)
{
printf("Enter a string to Enc:");
scanf("%s", str1);
Enc(str1, shift % 26);
printf("Encrypted string: %s\n", str1);
}
else if (input == 2)
{
printf("Enter a string to Dec:");
scanf("%s", str2);
Dec(str2, shift % 26);
printf("Decrypted string: %s\n", str2);
}
else if (input == 3)
break;
else
{
printf("ERROR\n");
goto arrow;
}
}
return 0;
}
}
6 changes: 0 additions & 6 deletions level1/p06_hanoi/main.c

This file was deleted.

49 changes: 49 additions & 0 deletions level1/p06_hanoi/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#include <iostream>
using namespace std;
string str = "A -> C ";
string shift1(string str)
{
for(int i = 0;i<str.length();i++)
{
if(str[i]=='B')
{
str[i] = 'C';
continue;
}
if(str[i]=='C')
str[i]='B';
}
return str;
}
string shift2(string str)
{
for(int i = 0;i<str.length();i++)
{
if(str[i]=='A')
{
str[i] = 'B';
continue;
}
if(str[i]=='B')
str[i]='A';
}
return str;
}
string Hanoi(int n)
{ if(n==1)
return str;
if(n>1)
return
shift1(Hanoi(n-1))+
str+
shift2(Hanoi(n-1));
}
int main()
{
int x = 0;
cout<<"Please input the number of plate:";
cin>>x;
cout<<endl<<Hanoi(x);
return 0;
}

Loading