0%

中国矿业大学数据结构作业3

2023 CUMT 中国矿业大学 数据结构课程 课后作业题 代码题解

本博文由我的GitHub仓库LymoneLM/LymoneTest代码自动整理生成,进入仓库可以查看最新的代码

如果代码对您有帮助,希望可以给我的仓库点个Star,或者在GitHub关注我,感谢

在我的个人博客莱蒙黎梦可以查看本博文原文和更多其他我的博文

本博文提供的代码仅供参考学习,原题已遗失,先尝试后使用,不同年度课程题目可能略有差异

A.cpp

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#include <bits/stdc++.h>
#pragma GCC optimize(2)
#define endl "\n"
#define ll long long
#define mm(a) memset(a,0,sizeof(a))
using namespace std;

bool matrix[110][110];
bool flag[110];
int m,n,cnt;

void find(int x){
cout<<x<<" ";
flag[x]=true;
for(int i=0;i<m;i++)
if(matrix[x][i]&&!flag[i])
find(i);
}

int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);

mm(matrix);
mm(flag);
cin>>m>>n;
cnt=0;
int tempx,tempy;
for(int i=0;i<n;i++){
cin>>tempx>>tempy;
matrix[tempx][tempy]=true;
matrix[tempy][tempx]=true;
}
find(0);

return 0;
}

B.cpp

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#include <bits/stdc++.h>
#pragma GCC optimize(2)
#define endl "\n"
#define ll long long
#define mm(a) memset(a,0,sizeof(a))
using namespace std;

int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);

int dat[65538];
cin>>dat[0];
for(int i=1;i<=dat[0];i++)
cin>>dat[i];


return 0;
}

C.cpp

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#include <bits/stdc++.h>
#pragma GCC optimize(2)
#define endl "\n"
#define mm(a) memset(a, 0, sizeof(a))
using namespace std;
int find(int *dat, int n, const int x) {
if(n==0) return -1010;
return 1 + (dat[n / 2] == x ? 0 : (dat[n / 2] > x ? find(dat, n / 2, x) : find(dat + n / 2 + 1, n - n / 2 - 1, x)));
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);

int N, dat[1010];
cin>>N;
for (int i = 0; i <= N; i++)
cin >> dat[i];
int x=find(dat, N, dat[N]);
if(x>0)
cout<<x<<endl;
else
cout<<"NO"<<endl;

return 0;
}

D.cpp

1
2
3
4
5
6
7
8
9
10
11
12
#include <bits/stdc++.h>
using namespace std;
int main() {

int N,x,dat[100];
cin>>N;x=N;
while(x--) cin>>dat[x];
sort(dat,dat+N,greater<int>());
while(N--) cout<<dat[N]<<" \n"[N==0?1:0];

return 0;
}

E.cpp

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include <bits/stdc++.h>
#pragma GCC optimize(2)
#define endl "\n"
#define ll long long
#define mm(a) memset(a,0,sizeof(a))
using namespace std;

int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);

int N,search,dat[110][2];cin>>N;
string name[110];
for(int i=0;i<N;i++)
cin>>dat[i][0]>>name[i]>>dat[i][1];
cin>>search;
for(int i=0;i<N;i++)
if(dat[i][0]==search)
cout<<name[i]<<" "<<dat[i][1]<<endl;

return 0;
}

编程作业、大作业、课程设计程序代码调试、协助/指导,制作软件/脚本/网页,经验丰富质量高

支持C/C++、JAVA、Python、Matlab、JavaScript、R语言等,欢迎咨询

企鹅:3451216814

-------------本文结束感谢您的阅读-------------

欢迎关注我的其它发布渠道