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

level-01-zhouzijian #9

Open
wants to merge 30 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
16c6807
Create p01_runningLetter
Kailai1104 Mar 9, 2021
113fd92
Create p02_isPrime
Kailai1104 Mar 9, 2021
b4d24fa
Create p03_Diophantus
Kailai1104 Mar 9, 2021
e8012e7
Create p04_ narcissus
Kailai1104 Mar 9, 2021
83c7a29
Create p05_allPrimes
Kailai1104 Mar 9, 2021
3e648f3
Create p06_Goldbach
Kailai1104 Mar 9, 2021
be41fbb
Update p06_Goldbach
Kailai1104 Mar 9, 2021
6695f88
Create 汉诺塔
Kailai1104 Mar 10, 2021
6734219
Update and rename 汉诺塔 to p08_hanoi
Kailai1104 Mar 10, 2021
89105f1
Create p09_maze
Kailai1104 Mar 13, 2021
96003c0
Update p01_runningLetter
Kailai1104 Mar 16, 2021
53ad6f8
Create p07_encrypt_decrypt
Kailai1104 Mar 16, 2021
afd3607
Create p11_linkedList
Kailai1104 Mar 23, 2021
8872a2f
Update p11_linkedList
Kailai1104 Mar 23, 2021
01a18d7
Rename p01_runningLetter to p01_runningLetter.cpp
Kailai1104 Mar 30, 2021
09ca387
Rename p02_isPrime to p02_isPrime.cpp
Kailai1104 Mar 30, 2021
b7e1499
Rename p03_Diophantus to p03_Diophantus.cpp
Kailai1104 Mar 30, 2021
c89c432
Rename p04_ narcissus to p04_narcissus.cpp
Kailai1104 Mar 30, 2021
1dcb458
Rename p05_allPrimes to p05_allPrimes.cpp
Kailai1104 Mar 30, 2021
2b97a42
Rename p06_Goldbach to p06_Goldbach.cpp
Kailai1104 Mar 30, 2021
d5de3eb
Rename p07_encrypt_decrypt to p07_encrypt_decrypt.cpp
Kailai1104 Mar 30, 2021
6007304
Rename p08_hanoi to p08_hanoi.cpp
Kailai1104 Mar 30, 2021
78b9e44
Update and rename p09_maze to p09_maze.cpp
Kailai1104 Mar 30, 2021
ceab9e9
Rename p11_linkedList to p11_linkedList.cpp
Kailai1104 Mar 30, 2021
89343a5
Update p11_linkedList.cpp
Kailai1104 Mar 30, 2021
f5a0ce3
Create p12_warehouse.cpp
Kailai1104 Apr 5, 2021
ece2bdf
Update p09_maze.cpp
Kailai1104 Apr 5, 2021
0243059
Add files via upload
Kailai1104 Apr 5, 2021
7701f89
Add files via upload
Kailai1104 Apr 5, 2021
c1f4c30
Update p10_pushboxs.cpp
Kailai1104 Apr 5, 2021
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
11 changes: 11 additions & 0 deletions 0.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
9 9
0 0 0 0 0 0 0 0 0
3 1 1 1 1 1 1 1 0
0 1 1 1 1 1 1 1 0
0 1 1 1 2 1 1 1 0
0 1 1 1 1 1 1 1 0
0 1 1 1 1 1 1 1 0
0 1 1 1 1 1 1 1 0
0 1 1 1 1 1 1 1 1
0 0 0 0 0 0 0 0 0

4 changes: 4 additions & 0 deletions List.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
3
a 1444
b 600
c 99
17 changes: 17 additions & 0 deletions p01_runningLetter.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#include<bits/stdc++.h>
using namespace std;
int cnt;
bool flag;
int main()
{
while(1)
{
if(cnt==120) flag=1;
if(cnt==0) flag=0;
cout<<setw(cnt)<<'A';
system("cls");
if(!flag) cnt++;
else cnt--;
}
return 0;
}
18 changes: 18 additions & 0 deletions p02_isPrime.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#include<bits/stdc++.h>
using namespace std;
int n;
int main()
{
cin>>n;
int m=(int)sqrt(n)+1;
for(int i=2;i<m;i++)
{
if(n%i==0)
{
cout<<"NO"<<endl;
return 0;
}
}
cout<<"YES"<<endl;
return 0;
}
14 changes: 14 additions & 0 deletions p03_Diophantus.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#include<bits/stdc++.h>
using namespace std;
int main()
{
for(float i=1;;i++)
{
if(i/6+i/12+i/7+5+4==i/2)
{
cout<<i<<endl;
return 0;
}
}
return 0;
}
26 changes: 26 additions & 0 deletions p04_narcissus.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#include<bits/stdc++.h>
using namespace std;
int cub(int x)
{
return x*x*x;
}
bool nar(int x)
{
int sum=0;
int sum0=x;
while(x>0)
{
sum+=cub(x%10);
x/=10;
}
return sum==sum0;
}
int main()
{
for(int i=100;i<=999;i++)
{
if(nar(i)) cout<<i<<" ";
}
cout<<endl;
return 0;
}
25 changes: 25 additions & 0 deletions p05_allPrimes.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#include<bits/stdc++.h>
#include<time.h>
using namespace std;
int main()
{
int isprime[1000];
for(int i=0;i<=1000;i++)
{
isprime[i]=1;
}
for(int i=2;i<=1000;i++)
{
if(isprime[i]==1)
{
cout<<i<<" ";
for(int j=2;i*j<=1000;j++)
{
isprime[i*j]=0;
}
}
}
cout<<endl;
printf("Time used = %.4fs\n", (double)clock() / CLOCKS_PER_SEC);//单位秒
return 0;
}
29 changes: 29 additions & 0 deletions p06_Goldbach.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#include<bits/stdc++.h>
using namespace std;
int n,p[25]={2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97},r[3];
void dfs(int x,int s)
{
if(s>3) return;
else if(x==n && s==3 && r[0]<=r[1] && r[1]<=r[2])
{
cout<<r[0]<<"+"<<r[1]<<"+"<<r[2]<<"="<<n<<endl;
}
else
{
for(int i=0;i<25;i++)
{
if((x+p[i])<=n)
{
r[s]=p[i];
dfs(x+p[i],s+1);
}
}
}
}
int main()
{
cin>>n;
if(n<=5 || n>100) cout<<"error"<<endl;
else dfs(0,0);
return 0;
}
69 changes: 69 additions & 0 deletions p07_encrypt_decrypt.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
//本加密器目前仅支持对26个小写英文字母加密
#include<bits/stdc++.h>
#include<windows.h>
#include<conio.h>
using namespace std;
string w,mp="qazxswedcvfrtgbnhyujmkiolp";
void enc(void)
{
for(int i=0;i<w.length();i++)
{
w[i]=mp[w[i]-'a'];
}
}
void dec(void)
{
for(int i=0;i<w.length();i++)
{
w[i]=mp.find(w[i])+'a';
}
}
int main()
{
while(1)
{
int flag=0;
cout<<"请输入密文:";
cin>>w;
for(int i=0;i<w.length();i++)
{
if(w[i]<97 || w[i]>122)
{
cout<<endl<<"error";
Sleep(100);
system("cls");
flag=1;
break;
}
}
if(!flag)
{
system("cls");
break;
}
}
while(1)
{
cout<<"选择加密请按1,选择解密请按2。"<<endl;
char t=_getch();
if(t=='1')
{
enc();
break;
}
else if(t=='2')
{
dec();
break;
}
else
{
cout<<endl<<"error";
Sleep(100);
system("cls");
}
}
system("cls");
cout<<"结果为:"<<w<<endl;
return 0;
}
17 changes: 17 additions & 0 deletions p08_hanoi.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#include<bits/stdc++.h>
using namespace std;
void hano(int n,char a,char b,char c)//n是准备移动的块数,a是起始柱,b是中间柱,c是目标柱;
{
if(n==0) return;
hano(n-1,a,c,b);//先将第n个盘子上的n-1个盘子从a移到b;
printf("将第%d号盘子从%c柱移动到%c柱\n",n,a,c);
hano(n-1,b,c,a);//再将n-1个盘子从b移到c,完成任务;
}
int main()
{
cout<<"请输入盘子总数:";
int n;
cin>>n;
hano(n,'A','B','C');
return 0;
}
110 changes: 110 additions & 0 deletions p09_maze.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
//此程序的地图是用深度优先搜素算法(dfs)随机生成的!
#include<bits/stdc++.h>
#include <conio.h>
using namespace std;
int xx[]={1,-1,0,0},yy[]={0,0,1,-1},v[44][44],mp[44][44];
struct Node
{
int nx,ny;
}nod;
void dfs(int x,int y)
{
mp[x][y]=1;
if(x==1 && y==1) return;
int s=rand()%4;
for(int i=s;i<s+4;i++)
{
int dx=x+xx[i%4];
int dy=y+yy[i%4];
if(mp[dx][dy]==0 && dx>0 && dy>0 && dx<43 && dy<43 && v[dx][dy]==0)
{
int flag=0;
for(int k=0;k<4;k++)
{
int ddx=dx+xx[k];
int ddy=dy+yy[k];
if(mp[ddx][ddy]==1) flag++;
}
if(flag==1)//保证不和别的路挖穿,增加迷宫难度;
{
v[dx][dy]=1;
dfs(dx,dy);
}
}
else v[dx][dy]=1;
}
}
int main()
{
for(int i=0;i<44;i++)
{
for(int j=0;j<44;j++) mp[i][j]=0;
}
dfs(42,42);
mp[1][0]=2;
mp[42][43]=1;
for(int i=0;i<44;i++)
{
for(int j=0;j<44;j++)
{
if(mp[i][j]==1) cout<<" ";
else if(mp[i][j]==0) cout<<"口";
else if(mp[i][j]==2) cout<<"人";
}
cout<<endl;
}
nod.nx=1;
nod.ny=0;
while(1)
{
int x0=nod.nx;
int y0=nod.ny;
if(x0==42 && y0==43)
{
cout<<"恭喜你,通关了!"<<endl;
system("pause");
break;
}
int x1,y1;
char t=_getch();
if(t=='w')
{
x1=x0-1;
y1=y0;
}
else if(t=='s')
{
x1=x0+1;
y1=y0;
}
else if(t=='a')
{
x1=x0;
y1=y0-1;
}
else if(t=='d')
{
x1=x0;
y1=y0+1;
}
if(mp[x1][y1]==1)
{
nod.nx=x1;
nod.ny=y1;
mp[x0][y0]=1;
mp[x1][y1]=2;
system("cls");
for(int i=0;i<44;i++)
{
for(int j=0;j<44;j++)
{
if(mp[i][j]==1) cout<<" ";
else if(mp[i][j]==0) cout<<"口";
else if(mp[i][j]==2) cout<<"人";
}
cout<<endl;
}
}
}
return 0;
}
Loading